首页 \ 问答 \ Struts2输入结果:它是如何工作的?(Struts2 INPUT result: how does it work? How are conversion / validation errors handled?)

Struts2输入结果:它是如何工作的?(Struts2 INPUT result: how does it work? How are conversion / validation errors handled?)

主要问题

工作流程应该是这样的:如果输入的字符串不是数字,首先应该通过一个异常拦截器,并且当通过param拦截器时,在转换为int类型时,它不能使用Integer.parseInt来完成Integer.parseInt并会发生异常; 不应该将那个异常(即NumberFormatException )推入值栈? 为什么它不显示NumberFormatException并显示结果,即使结果不应被打印?

侧面问题

每当我在表单中添加一个字母时,它就会变成零...? 为什么这样 ?

的index.jsp

<%@ taglib uri="/struts-tags" prefix="s"%>
<s:form action="divide">
    <s:textfield name="number1" label="number1"/>
    <s:textfield name="number2" label="number2"/>
    <s:submit value="divide"/>
</s:form>

divide.java

package actions;

public class divide {
    int number1,number2,result;
    public String execute() throws Exception
    {
        result=number1/number2;
        return "success";
    }
    public int getNumber1() {
        return number1;
    }
    public void setNumber1(int number1) {
        this.number1 = number1;
    }
    public int getNumber2() {
        return number2;
    }
    public void setNumber2(int number2) {
        this.number2 = number2;
    }
    public int getResult() {
        return result;
    }


}

result.jsp中

<%@taglib uri="/struts-tags" prefix="s" %>
<b>
    the result of division is
    <s:property value="result"/>
</b>
<jsp:include page="index.jsp"></jsp:include>

处理程序jsp

<%@taglib uri="/struts-tags" prefix="s"%>
<b>
    following exception occured during the processing
    <s:property value="exception"/>
</b>
<jsp:include page="index.jsp"/>

在struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        <package name="yo" extends="struts-default">
            <action name="divide" class="actions.divide">
                <exception-mapping result="error" exception="Exception"/>
                <result name="success">/result.jsp</result>
                <result name="error">/handler.jsp</result>
            </action>
        </package>
    </struts>

Main Question

The work flow should be like this: if an String is entered other than a number, first it should pass through a exception interceptor, and when passing through param interceptor, while converting to int type, it wont be able to do it using Integer.parseInt and an exception would occur; shouldn't that exception (that is NumberFormatException) be pushed into Value Stack ? Why does it not show NumberFormatException and show the result even though result should not be printed instead ?

Side Question

Whenever I add an alphabet in the form, it changed to zero...? Why so ?

index.jsp

<%@ taglib uri="/struts-tags" prefix="s"%>
<s:form action="divide">
    <s:textfield name="number1" label="number1"/>
    <s:textfield name="number2" label="number2"/>
    <s:submit value="divide"/>
</s:form>

divide.java

package actions;

public class divide {
    int number1,number2,result;
    public String execute() throws Exception
    {
        result=number1/number2;
        return "success";
    }
    public int getNumber1() {
        return number1;
    }
    public void setNumber1(int number1) {
        this.number1 = number1;
    }
    public int getNumber2() {
        return number2;
    }
    public void setNumber2(int number2) {
        this.number2 = number2;
    }
    public int getResult() {
        return result;
    }


}

result.jsp

<%@taglib uri="/struts-tags" prefix="s" %>
<b>
    the result of division is
    <s:property value="result"/>
</b>
<jsp:include page="index.jsp"></jsp:include>

handler jsp

<%@taglib uri="/struts-tags" prefix="s"%>
<b>
    following exception occured during the processing
    <s:property value="exception"/>
</b>
<jsp:include page="index.jsp"/>

struts.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC 
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        <package name="yo" extends="struts-default">
            <action name="divide" class="actions.divide">
                <exception-mapping result="error" exception="Exception"/>
                <result name="success">/result.jsp</result>
                <result name="error">/handler.jsp</result>
            </action>
        </package>
    </struts>

原文:https://stackoverflow.com/questions/23448616
更新时间:2023-02-13 21:02

最满意答案

sizeof(int)==4 (请求4GB)的32位x86系统上,这种分配是不可能的。 进程的总地址空间限制为4GB,并且进程本身通常被限制为小于32GB Windows的2GB或3GB,具体取决于boot.ini设置和Windows版本,不确定64bit Windows上32位进程的限制,但4GB根本不可能)。

对于64位的情况,你需要有4GB的虚拟内存来支持分配才能成功。


That allocation is simply not possible on 32bit x86 systems with sizeof(int)==4 (you are requesting 4GB). A process's total address space is limited to 4GB, and the process itself is usually limited to less than that (2GB or 3GB for 32bit Windows depending on boot.ini settings and the Windows edition, not sure which limit applies for 32bit processes on 64bit Windows, but 4GB is simply not possible).

For the 64bit case, you'd need to have 4GB of virtual memory available to back that allocation for it to succeed.

相关问答

更多
  • 我的直觉如下。 堆栈不像堆那么容易管理。 堆栈需要存储在连续存储器中。 这意味着您无法根据需要随机分配堆栈,但您至少需要为此目的预留虚拟地址。 保留的虚拟地址空间的大小越大,可以创建的线程越少。 例如,32位应用程序通常具有2GB的虚拟地址空间。 这意味着如果堆栈大小为2MB(在pthreads中为默认值),则最多可以创建1024个线程。 这对于诸如Web服务器之类的应用来说可能很小。 将堆栈大小增加到例如100MB(即,您保留100MB,但不一定立即为堆栈分配100MB),将线程数限制为约20,即使对于简 ...
  • BigInteger.Pow BigInteger将是一个大量复杂的数字。 二进制乘法具有这样的性质,即粗略地讲,将一个n位数乘以一个m位数产生一个近似(n+m)位的答案。 10 * 4096 = 0b1010 * 0b1_0000_0000_0000 (4 bits, 13 bits) 40960 = 0b1010_0000_0000_0000 (16 bits) 16 * 4096 = 0b1_0000 * 0b1_0000_0000_0000 (5 bits, 13 bits) 65536 = ...
  • 所以,如果你想要一个包含10个整数的数组,你就会写: int arr[10]; 但是如果你想做这样的事情呢? cout << "How many?"; cin >> num; int arr[num]; 好吧,C ++语言不允许这样做。 相反,你必须这样做: int *arr = new int[num]; 创建你的数组。 以后你必须[1]使用: delete [] arr; 释放记忆。 那么,这是如何工作的? 当您调用new时,C ++运行时库[您不必编写构成C ++基础的代码]将计算出多 ...
  • vector::max_size()与单个向量的大小有关,在没有任何其他内存使用的情况下。 没有一个向量接近这个大小。 最大的是5000,个人分配5000 * max(sizeof(vector), sizeof(Case)) ,对我来说是80,000。 您看到的错误是所有25,000,000个Cases和500,000,000个Couches的总分配超出了程序中的地址空间 vector::max_size() relates to how big a single vector can get ...
  • 在sizeof(int)==4 (请求4GB)的32位x86系统上,这种分配是不可能的。 进程的总地址空间限制为4GB,并且进程本身通常被限制为小于32GB Windows的2GB或3GB,具体取决于boot.ini设置和Windows版本,不确定64bit Windows上32位进程的限制,但4GB根本不可能)。 对于64位的情况,你需要有4GB的虚拟内存来支持分配才能成功。 That allocation is simply not possible on 32bit x86 systems with ...
  • 在你的代码中: bankAccount account[10]; ... for (int i = 0; i < sizeof(account); i++) 循环迭代中存在问题(特别是上限 )。 您的account数组包含您的bankAccount类的10个实例。 很明显,你的意图是迭代所有的数组项。 为了正常工作, i循环索引的有效值为0,1,2,3,...,9.所以,如果sizeof(account)返回10(实际上,你使用<运算符,排除10的上限,并且在9之前停止一个值,这是正确的)。 问题是s ...
  • 对不起,你最好使用alloca而不是做那种东西。 不仅它是x86特定的,而且如果在优化上进行编译,它可能会带来意想不到的结果。 alloca被许多编译器支持,所以你不应该很快遇到问题。 Sorry, but you'd be better off using alloca than doing that kind of stuff. Not only it's x86 specific, but also, it'll probably give unexpected results if compiled ...
  • 该错误消息可能来自ntdll.dll中的HeapAlloc() 。 我可以使用以下代码重现该消息: HANDLE hHeap = HeapCreate(0, 0, 4096); LPVOID p = HeapAlloc(hHeap, 0, 0x99999998); 消息由ntdll.dll中的DbgPrint()发送到调试器输出窗口,所以我会尝试在那里设置一个断点(它是一个导出的函数,所以你不需要一个符号文件来找到它的地址)然后看着你的调用堆栈。 The error message is probably ...
  • 在Boost Iterator库和C ++ 14的通用lambdas的帮助下: #include #include #include #include int main() { std::set s1 { 1,2,3,4 }; std::set s2 { 3,4,5,6 }; int i = 0; auto counter ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)