Struts 2输入结果:它是如何工作的?转换/验证错误是如何处理的?
主要问题
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>
相关分类