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 isNumberFormatException
) be pushed into Value Stack ? Why does it not showNumberFormatException
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
最满意答案
在
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 onboot.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.
相关问答
更多-
c语言之后还可以学什么[2022-05-01]
c++ -
我的直觉如下。 堆栈不像堆那么容易管理。 堆栈需要存储在连续存储器中。 这意味着您无法根据需要随机分配堆栈,但您至少需要为此目的预留虚拟地址。 保留的虚拟地址空间的大小越大,可以创建的线程越少。 例如,32位应用程序通常具有2GB的虚拟地址空间。 这意味着如果堆栈大小为2MB(在pthreads中为默认值),则最多可以创建1024个线程。 这对于诸如Web服务器之类的应用来说可能很小。 将堆栈大小增加到例如100MB(即,您保留100MB,但不一定立即为堆栈分配100MB),将线程数限制为约20,即使对于简 ...
-
如何在C#中创建非对称密钥,因为指数大小有限?(How to create asymmetric keys in C# because of limited exponent size?)[2023-03-18]
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 ++基础的代码]将计算出多 ...
-
C ++向量上的分配错误(allocation error on C++ vector)[2022-06-16]
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 ... -
有限的分配大小C ++(The limited allocation size C++)[2023-10-08]
在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 ...
-
C ++中的动态堆栈分配(Dynamic stack allocation in C++)[2023-06-05]
对不起,你最好使用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 ...