日期:2014-05-17 浏览次数:20796 次
import com.opensymphony.xwork2.ActionSupport; import com.lee.user.user.*; public class LoginActionForm extends ActionSupport{ User us = new User(); public String execute(){ System.out.println("username:"+us.getUserName()); System.out.println("password:"+us.getPassWord()); return SUCCESS; } }
public class User { private String UserName; private String PassWord; /** * @return the userName */ public String getUserName() { return UserName; } /** * @param userName the userName to set */ public void setUserName(String userName) { UserName = userName; } /** * @return the passWord */ public String getPassWord() { return PassWord; } /** * @param passWord the passWord to set */ public void setPassWord(String passWord) { PassWord = passWord; } }
<s:form action="login" method="post"> <s:textfield name="UserName" label="用户名"></s:textfield> <s:password name="PassWord" label="密码"></s:password> <s:submit label="登陆" value="登陆"></s:submit> </s:form>
<package name="default" namespace="/" extends="struts-default"> <action name="loginindex"> <result>login.jsp</result> </action> <action name="login" class="com.lee.user.form.LoginActionForm"> <result name="success">wellcom.jsp</result> <result name="error">error.jsp</result> </action> <action name="goback"> <result name="success">login.jsp</result> </action> </package>
<welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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>