在环境搭好的情况下,(不会的找我)首先需要编写Action,代码如下:
private int one; private int two; private int san; public int getSan() { return san; } public void setSan(int san) { this.san = san; } public int getOne() { return one; } public void setOne(int one) { this.one = one; } public int getTwo() { return two; } public void setTwo(int two) { this.two = two; } public String login() { if(one>0&&two>0){ san=one+two; return "success"; } else return "error"; } }
其次在写Struts.xml文件,代码如下:
<struts>
<constant name="struts.i18n.encoding" value="utf-8"></constant>
<constant name="struts.multipart.maxSize" value="20971520" />
<constant name="struts.devMode" value="true" />
<package name="p_user" namespace="/" extends="struts-default">
<action name="login" class="com.cqvie.action.UserAction"
method="login">
<result name="success">
/login_success.jsp
</result>
<result name="error">
/login_error.jsp
</result>
</action>
</package>
</struts>
最后便是计算界面和计算结果界面,代码如下:
<body>
<form action="login" method="post" align="center">
<input type="text" name="one" style="width:100px"/>
+
<input type="text" name="two" style="width:100px"/>
<input type="submit" value="计算" />
</form>
</body>
<body>
<form align="center">
计算结果为:${san}
</form>
</body>
运行界面图片就不给大家看了!
原文:http://www.cnblogs.com/sy399/p/6508684.html