struts2配置(namespace,include,method的使用)
2011-06-21 22:17
260 查看
接着复习吧,每天晚上有时间就做几个小例子,是谁偷走了我的时间?
常用的一些配置namespace,include,method的使用.
namespace,include用于组织项目中的多个模块
method用于指定action执行的方法
组织图:
struts.xml:
struts-dept.xml:
struts-emp.xml:
HelloAction.java:
EmpAction.java与DeptAction.java与HelloAction.java相似,略.
常用的一些配置namespace,include,method的使用.
namespace,include用于组织项目中的多个模块
method用于指定action执行的方法
组织图:
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <constant name="struts.devMode " value="true" /> <!-- namespace 好像必须指定哦(2.1.8中至少应该写个/) / 代表根,即web应用上下文 name与namespace 可以设置为模块的名称 method属性的作用:调用action中对应的方法,以下面为例:对于method=list,即调用HelloAction中的list或doList方法 当没有指定method属性时,默认调用execute方法 注:action中的list或doList方法签名要与execute方法一致 --> <package name="struts2Prac" extends="struts-default" namespace="/"> <action name="hello" class="cn.enjoylife.prac.action.HelloAction"> <result name="success" >/success.jsp</result> </action> <action name="helloList" class="cn.enjoylife.prac.action.HelloAction" method="list"> <result name="success" >/success.jsp</result> </action> <action name="helloDelete" class="cn.enjoylife.prac.action.HelloAction" method="delete"> <result name="success" >/success.jsp</result> </action> </package> <!-- include可以管理多个struts xml文件 --> <include file="cn/enjoylife/prac/resource/struts-emp.xml"/> <include file="cn/enjoylife/prac/resource/struts-dept.xml"/> </struts>
struts-dept.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="dept" extends="struts-default" namespace="/dept"> <action name="deptAct" class="cn.enjoylife.prac.action.DeptAction"> <result name="success">/success.jsp</result> </action> </package> </struts>
struts-emp.xml:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="emp" extends="struts-default" namespace="/emp"> <action name="empAct" class="cn.enjoylife.prac.action.EmpAction"> <result name="success" >/success.jsp</result> </action> </package> </struts>
HelloAction.java:
public class HelloAction extends ActionSupport { private static final long serialVersionUID = 6832032564761957243L; private String hello; public String getHello() { return hello; } public void setHello(String hello) { this.hello = hello; } @Override public String execute() throws Exception { System.out.println("execute..."); return SUCCESS; } public String doList() throws Exception { System.out.println("list..."); return SUCCESS; } public String doDelete() throws Exception { System.out.println("delete..."); return SUCCESS; } }
EmpAction.java与DeptAction.java与HelloAction.java相似,略.
相关文章推荐
- struts2自主学习之动态方法调用,使用method属性,配置Result,结果类型
- 关于struts2的配置文件,namespace的使用
- Struts2 的 struts.xml 配置中 namespace 的使用
- Struts2 的 struts.xml 配置中 namespace 的使用
- Struts2的struts.xml配置中的namespace的使用
- Struts2配置文件中使用通配符收藏method="{1}"
- Struts2 的 struts.xml 配置中 namespace 的使用
- Struts2 的 struts.xml 配置中 namespace 的使用
- Struts2的struts.xml配置中的namespace的使用
- Struts2-Action接受参数方式、method属性使用及通配符的配置
- Struts2 的 struts.xml 配置中 namespace 的使用
- Struts2 的 struts.xml 配置中 namespace 的使用
- Struts2 的 struts.xml 配置中 namespace 的使用
- struts2 配置json格式数据( includeProperties中对list集合的正则配置)
- 【Struts2复习知识点二】-namespace的配置
- Maven resource 配置中include与exclude及其filter的使用
- struts2配置文件中method="{1}"详解
- struts2 中使用 json需要的jar包以及配置
- Struts2 namespace的使用
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射