struts2分模块与action生命周期
程序员文章站
2022-07-12 16:13:54
...
1. 分模块
2. 生命周期
struts.xml <include file=""></include> 新建项目HeadFirstStruts2Chap02_04
CheLiangAction.java package com.andrew.action; import com.opensymphony.xwork2.ActionSupport; public class CheLiangAction extends ActionSupport { @Override public String execute() throws Exception { System.out.println("执行了CheLiangAction Action的默认方法"); return SUCCESS; } } ZiChanAction.java package com.andrew.action; import com.opensymphony.xwork2.ActionSupport; public class ZiChanAction extends ActionSupport { @Override public String execute() throws Exception { System.out.println("执行了ZiChanAction Action的默认方法"); return SUCCESS; } } cheliang.xml <package name="cheliang" namespace="/cheliang" extends="struts-default"> <action name="cheliang" class="com.andrew.action.CheLiangAction"> <result name="success">${pageContext.request.contextPath}/success.jsp</result> </action> </package> zichan.xml <package name="zichan" namespace="/zichan" extends="struts-default"> <action name="zichan" class="com.andrew.action.ZiChanAction"> <result name="success">${pageContext.request.contextPath}/success.jsp</result> </action> </package> struts.xml <struts> <include file="cheliang.xml"/> <include file="zichan.xml"/> </struts> success.jsp Ok! http://localhost:8080/HeadFirstStruts2Chap02_04/cheliang/cheliang Ok! 执行了CheLiangAction Action的默认方法 http://localhost:8080/HeadFirstStruts2Chap02_04/zichan/zichan Ok! 执行了ZiChanAction Action的默认方法
2. 生命周期
新建项目HeadFirstStruts2Chap02_06
HelloAction.java package com.andrew.action; import com.opensymphony.xwork2.ActionSupport; public class HelloAction extends ActionSupport { public HelloAction() { System.out.println(this); } @Override public String execute() throws Exception { return SUCCESS; } } struts.xml <package name="manage" namespace="/" extends="struts-default"> <action name="hello" class="com.andrew.action.HelloAction"> <result name="success">success.jsp</result> </action> </package> success.jsp Ok! http://localhost:8080/HeadFirstStruts2Chap02_06/hello com.andrew.action.HelloAction@1e3ec646 http://localhost:8080/HeadFirstStruts2Chap02_06/hello com.andrew.action.HelloAction@46867b6b
上一篇: struts2配置result
下一篇: struts2配置struts.xml
推荐阅读
-
解决JSP与struts2 Action中文乱码问题
-
struts2与spring整合后 action怎么做多例 服务层为什么不用手动注入
-
struts2与spring整合后 action怎么做多例 服务层为什么不用手动注入
-
Struts2中Action由Struts2自己管理与由Spring管理的区别(转自别人)
-
struts2分模块与action生命周期
-
Struts2配置文件模块化包含(include)与action总结
-
Python 二分查找与 bisect 模块
-
struts2之action生命周期,通配符,ActionSupport
-
Python 二分查找与 bisect 模块
-
解决JSP与struts2 Action中文乱码问题