struts--动态方法调用和使用通配符(8)

来源:互联网 发布:知乎英国脱欧利弊 编辑:程序博客网 时间:2024/06/06 04:14

8、为应用指定多个struts.xml文件(使用indclude)包含进来
<struts>
 <include file="struts_user.xml"/>
 <incllude file="struts_other.xml"/>
</struts>
配置文件包的名称要唯一

9.动态方法的调用和使用通配符定义
实现struts1中的DispathAction的效果
<action path="/control/employee/manage"
 type="...DispathAction"
 parameter="method"/>
struts2中的两种方式:
(1).动态方法调用
在Action名称的后面加"!"+方法名称就可以了,可以用一个常量禁止动态方法的调用
<constant name="struts.enable.Dynamic.MethodInvocation" value="false"/>
HashMap可以有Null的键和值 Hashtable不能
(2).使用通配符的方式 
<package name="employee" namespace="/control/employee" extends="sstruts-default">
 <action name="list_*" class="cn.itcast.action.HelloWorldAction" method="execute">
  <result name="success">/WEB-INF/page/message.jsp</result>
 </action>
</package>
还可以method="{1}"得到匹配的字符串
/action/employee/list_addUI.action

10.如何去接收请求参数
在struts1中通过ActionForm接收请求参数,属性和请求参数名称相同的情况下才接收,要提供
属性的set方法

在struts2中
在Action中定义与请求参数同名的属性,struts2便能够自动的接收请求参数,并赋予给同名的属性
/struts2通过反射技术调用与请求参数同名的属性和setter方法获取
 在jsp页面上上得到参数要用到get方法
<form action="<%request.getContextPath()%>/control/employee/listexecute_action">
....
</form>
使用复合类型接收请求参数
id:<input type="text" name="person.id"/>
在页面上El表达式:id=${person.id}

怎样能够接收person复合类型
拦截器接收到请求参数---请求参数名称---访问对应的属性----person为null,利用
反射技术,调用默认的构造方法生成对象,通过反射技术注入值

通过doFilter来解决乱码
doFilter{
 req.setCharacterEncoding("UTF-8");
 filterChain.doFilter(request,response);
}

原创粉丝点击