筹建Struts 2.1的开发环境,图文教程附源码
搭建Struts 2.1的开发环境,图文教程附源码public class UserAction extends ActionSupport{? ?? ???/**? ?
搭建Struts 2.1的开发环境,图文教程附源码
- public class UserAction extends ActionSupport
- {
- ? ?? ???/**
- ? ?? ?? ?* @author 中文demo站:Quanke
- ? ?? ?? ?* @url http://www.cndemoz.com
- ? ?? ?? ?* struts2处理类
- ? ?? ?? ?*/
- ? ?? ???private String userName;
- ? ?? ???private String userPwd;
- ? ?? ???
- ? ?? ???public String getUserName()? ?? ???//一定要是getUserName,因为在登陆页面提交的表单名的值是userName,有点java基础的人,相信你懂得,不懂请回帖
- ? ?? ???{
- ? ?? ?? ?? ?? ? return userName;
- ? ?? ???}
- ? ?? ???public void setUserName(String userName)//一定要是setUserName,因为在登陆页面提交的表单名的值是userName
- ? ?? ???{
- ? ?? ?? ?? ?? ? this.userName = userName;
- ? ?? ???}
- ? ?? ???public String getUserPwd()
- ? ?? ???{
- ? ?? ?? ?? ?? ? return userPwd;
- ? ?? ???}
- ? ?? ???public void setUserPwd(String userPwd)
- ? ?? ???{
- ? ?? ?? ?? ?? ? this.userPwd = userPwd;
- ? ?? ???}
- ? ?? ???/*
- ? ?? ?? ?* struts2默认寻找的方法,方法名不可写错
- ? ?? ?? ?* (non-Javadoc)
- ? ?? ?? ?* @see com.opensymphony.xwork2.ActionSupport#execute()
- ? ?? ?? ?*/
- ? ?? ???@Override
- ? ?? ???public String execute() throws Exception
- ? ?? ???{
- ? ?? ?? ?? ?? ? //这里不写数据库
- ? ?? ?? ?? ?? ? if("cndemoz".equals(userName)){
- ? ?? ?? ?? ?? ?? ?? ?? ?return SUCCESS;//继承了ActionSupport类,ActionSupport类声明了SUCCESS静态属性,值为success,所以在struts.xml文件中的result元素的属性name的值为success
- ? ?? ?? ?? ?? ? }
- ? ?? ?? ?? ?? ? return INPUT;? ?? ???//继承了ActionSupport类,ActionSupport类声明了INPUT静态属性,值为input,所以在struts.xml文件中的result元素的属性name的值为input
- ? ?? ???}
- }
复制代码原文地址:http://www.cndemoz.com/thread-126-1-1.html