struts2的流程跳转
2015-10-26 13:33
323 查看
最近在做了一个关于struts2的小示例,对struts2的知识点重新梳理了一下,现在根据自己的理解总结一下,有什么不对的地方还望给予指出从登陆页面开始index.jsp:
<body> <form action="/arch4demo/login.do" method="post"> <table align="center"> <tr><td colspan="2"><h2>员工签到系统登录页面</h2></td></tr> <tr><td>员工号:</td><td><input type="text" name="employee_id"/></td></tr> <tr><td>密 码:</td><td><input type="password" name="employee_pwd"/></td></tr> <tr><td> </td><td> </td></tr> <tr><td><input type="submit" value="登陆"/></td><td><input type="reset" value="重置"/></td></tr> </table> </form> </body>当填入员工号和密码点击登陆按钮后,struts2会根据拦截器拦截页面form里action请求,在web.xml配置的拦截器如下:
<span style="white-space:pre"> </span><filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <span style="white-space:pre"> </span><filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping>
<pre name="code" class="html"><span style="background-color: rgb(255, 255, 255);">当struts2的拦截器拦截后会跳转到struts2的配置文件struts2.xml中,找到对应的action(与index.jsp页面form里的action名字相对应)</span>
<pre name="code" class="html"><package name="default" namespace="/" extends="struts-default"></span> <action name="login" class="loginAction" method="login"> <result name="success">success.jsp</result> <result name="error">index.jsp</result> </action> </package>然后跳转到名为login的Action类里:
public class LoginAction extends Struts2Action {private Login login;private Integer id;private String pwd;private Integer grade;public Login getLogin() {return login;}public void setLogin(Login login) {this.login = login;}public LoginService getLoginService() {return loginService;}public void setLoginService(LoginService loginService) {this.loginService = loginService;}public LoginAction(){}public Integer getId() {return id;}public void setId(Integer id) {this.id = id;}public String getPwd() {return pwd;}public void setPwd(String pwd) {this.pwd = pwd;}public Integer getGrade() {return grade;}public void setGrade(Integer grade) {this.grade = grade;}public String login(){if(findUserId()){return "success";}else{return "error";}}}根据login方法执行后返回的结果,在struts.xml的配置信息跳转到对应的页面。总体流程是项目启动后,加载web.xml文件,根据页面form的action请求,拦截器拦截请求在struts.xml寻找对应名字的action,然后执行对应的XxxAction指定名的方法,执行返回的结果再根据struts.xml跳转到相应的页面
相关文章推荐
- Struts - 标签库
- struts1.0于struts2.0的比较
- Struts2中关于namespace的学习心得
- Struts2----自定义action的学习心得
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!welcome] associ
- struts 学习笔记
- struts2.0拦截器(实现未登录的用户不能访问系统的页面)(转)
- 软件开发疑惑解答
- struts2登陆拦截器
- struts2框架原理
- web.xml
- web.xml
- struts2框架原理
- struts2登陆拦截器
- liferay中配置Struts2
- Struts2部署后抛出404 Tomcat work目录下均为空目录
- struts2 拦截器和actioninvocation
- Struts2拦截器配置
- struts2学习01——工程搭建
- struts2学习02——配置文件