读书人

筹建Struts 2.1的开发环境,图文教程附

发布时间: 2012-10-15 09:45:25 作者: rapoo

搭建Struts 2.1的开发环境,图文教程附源码

  1. public class UserAction extends ActionSupport
  2. {
  3. ? ?? ???/**
  4. ? ?? ?? ?* @author 中文demo站:Quanke
  5. ? ?? ?? ?* @url http://www.cndemoz.com
  6. ? ?? ?? ?* struts2处理类
  7. ? ?? ?? ?*/
  8. ? ?? ???private String userName;
  9. ? ?? ???private String userPwd;
  10. ? ?? ???
  11. ? ?? ???public String getUserName()? ?? ???//一定要是getUserName,因为在登陆页面提交的表单名的值是userName,有点java基础的人,相信你懂得,不懂请回帖
  12. ? ?? ???{
  13. ? ?? ?? ?? ?? ? return userName;
  14. ? ?? ???}

  15. ? ?? ???public void setUserName(String userName)//一定要是setUserName,因为在登陆页面提交的表单名的值是userName
  16. ? ?? ???{
  17. ? ?? ?? ?? ?? ? this.userName = userName;
  18. ? ?? ???}
  19. ? ?? ???public String getUserPwd()
  20. ? ?? ???{
  21. ? ?? ?? ?? ?? ? return userPwd;
  22. ? ?? ???}
  23. ? ?? ???public void setUserPwd(String userPwd)
  24. ? ?? ???{
  25. ? ?? ?? ?? ?? ? this.userPwd = userPwd;
  26. ? ?? ???}

  27. ? ?? ???/*
  28. ? ?? ?? ?* struts2默认寻找的方法,方法名不可写错
  29. ? ?? ?? ?* (non-Javadoc)
  30. ? ?? ?? ?* @see com.opensymphony.xwork2.ActionSupport#execute()
  31. ? ?? ?? ?*/
  32. ? ?? ???@Override
  33. ? ?? ???public String execute() throws Exception
  34. ? ?? ???{
  35. ? ?? ?? ?? ?? ? //这里不写数据库
  36. ? ?? ?? ?? ?? ? if("cndemoz".equals(userName)){
  37. ? ?? ?? ?? ?? ?? ?? ?? ?return SUCCESS;//继承了ActionSupport类,ActionSupport类声明了SUCCESS静态属性,值为success,所以在struts.xml文件中的result元素的属性name的值为success
  38. ? ?? ?? ?? ?? ? }
  39. ? ?? ?? ?? ?? ? return INPUT;? ?? ???//继承了ActionSupport类,ActionSupport类声明了INPUT静态属性,值为input,所以在struts.xml文件中的result元素的属性name的值为input
  40. ? ?? ???}
  41. }
复制代码

原文地址:http://www.cndemoz.com/thread-126-1-1.html

读书人网 >编程

热点推荐