日期:2014-05-20 浏览次数:20876 次
package action; public class LoginAction { 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 () throws Exception { if (getUsername().equals("admin")&&getPassword().equals("123")) { return("success"); } else { return("error"); } } }
<?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.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <action name="Login" class="action.LoginAction"> <result name="error">error.jsp</result> <result name="success">welcome.jsp</result> </action> </package> </struts>
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
<%@ page language="java" contentType="text/html;charset=GBK"%> <html> <head> <title>登陆页面</title> </head> <body> <form action="Login.action" method="post"> <table align="center"> <caption><h3>用户登陆</h3></caption> <tr> <td>用户名:<input type="text" name="username"/></td> </tr> <tr> <td> 密 码:<input type="text" name="password"/> </td> </tr> <tr align="center"> <td clospan="2"> <input type="submit" value="登陆"/><input type="reset" value="重填"/> </td> </tr> </table> </form> </body> </html>