Struts 2输入结果:它是如何工作的?转换/验证错误是如何处理的?主要问题工作流程应该是这样的:如果输入一个字符串而不是数字,首先它应该通过一个异常拦截器,而当通过param拦截器时,当转换为int类型时,它将不能使用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.javapackage 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>
添加回答
举报
0/150
提交
取消