日期:2014-05-20 浏览次数:20695 次
package mypack; import com.opensymphony.xwork2.ActionSupport; public class UserAction extends ActionSupport { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String execute() { if ("aaa".equals(getUsername())&& "bbb".equals(getPassword())) { return "success"; } else { return "error"; } } } 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> <constant name="struts.devMode" value="true" /> <package name="actions" extends="struts-default"> <action name="login" class="mypack.UserAction"> <result name="success">/success.jsp</result> <result name="error">/error.jsp</result> </action> </package> </struts> index.jsp <body> <form action="login.action" method="post"> name<input type=text name=username/><br/> pass<input type=text name=password/><br/> <input type=submit name=submit value="tijiao"> </form> </body> 下面两个一个是成功页,一个是错误页 <body> success <br> </body> <body> success <br> </body>