Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
odel() {
return user;
}
}
字符编码
配置:
<constant name="struts.i18n.encoding" value="GBK" /> <!-- internationalization -->
在struts2.1.6中不起作用,属于bug,在struts2.1.7中修改。
解决方案:
修改web.xml 中:
<filter>
<filter-name>struts2</filter-name>
<!-- struts2.1中使用filter -->
<!--<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>-->
<!-- struts2.0中使用的filter -->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
=============================================================
Struts2一个Action内包含多个请求处理方法的处理(三种方式)
Struts1提供了DispatchAction,从而允许一个Action内包含多个请求处理方法。Struts2也提供了类似的功能。处理方式主要有以下三种方式:
1.1. 动态方法调用:
DMI:Dynamic Method Invocation 动态方法调用。
动态方法调用是指:表单元素的action不直接等于某个Action的名字,而是以如下形式来指定对应的动作名:
<form method="post" action="userOpt!login.action">
则用户的请求将提交到名为”userOpt”的Action实例,Action实例将调用名为”login”方法来处理请求。同时login方法的签名也是跟execute()一样,即为public String login() throws Exception。
注意:要使用动态方法调用,必须设置Struts2允许动态方法调用,通过设置struts.enable.DynamicMethodInvocation常量来完成,该常量属性的默认值是true。
1.1.1. 示例:
修改用户登录验证示例,多增加一个注册用户功能。
1. 修改Action类:
package org.qiujy.web.struts2.action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
*@authorqiujy
*@version1.0
*/
publicclass LoginAction extends ActionSupport{
private String userName;
private String password;
private String msg; //结果信息属性
/**
*@returnthemsg
*/
public String getMsg() {
returnmsg;
}
/**
*@parammsgthemsgtoset
*/
publicvoid setMsg(String msg) {
this.msg = msg;
}
/**
*@returntheuserName
*/
public String getUserName() {
returnuserName;
}
/**
*@paramuserNametheuserNametoset
*/
publicvoid setUserName(String userName) {
this.userName = userName;
}
/**
*@returnthepassword
*/
public String getPassword() {
returnpassword;
}
/**
*@parampasswordthepasswordtoset
*/
publicvoid setPassword(String password) {
this.password = password;
}
/**
*处理用户请求的login()方法
*@return结果导航字符串
*@throwsException
*/
public String login() throws Exception{
Struts2一个Action内包含多个请求处理方法的处理_IT/计算机_专业资料。Struts2...为 Action 配置 method 属性: 将 Action 类中的每一个处理方法都定义成一个...
Struts2 一个 Action 内包含多个请求处理方法的处理 Struts2 一个 Action 内包含多个请求处理方法的处理(三种方式) Struts1 提供了 DispatchAction,从而允许一个 ...
Struts2 2010-07-11 Struts2一个Action内包含多个请求处理方法的处理(三种方式...动态方法调用: DMI:Dynamic Method Invocation 动态方法调用。 动态方法调用是指:...
的Action处理类 Action的动态方法调用一个Action内包含多个请求处理方法的处理 :...class="test.struts2.DMI.TestDMI" method="searchUsers"> <result>result.jsp...
1.1. 包配置: Struts2 框架中核心组件就是 Action、拦截器等,Struts2 框架...3. 一个 Action 内包含多个请求处理方法的处理 Struts1 提供了 DispatchAction,...
请求参数名的格式为 action!method.action 注:由于 Struts2 只需要参数名,因此,参数值是什么都可以。 下面我就给出一个实例程序来演示如何处理有多个 submit 的 ...
1) Struts2中最简单的要求就是你的Action类中要...此文件会自动包含到struts.xml中。 4) struts-...method: 指定处理这个请求的Action类的方法名。如果...
一个请求在 Struts2 Struts2框架中的处理步骤: a) 客户端初始化一个指向 Servlet 容器的请求; b) 根据 Web.xml 配置,请求首先经过 ActionContextCleanUp 过滤...
Struts2 中的Action 1 课程结构内容第一章:Struts2...Action: 业务逻辑控制器,负责处理单个特定请求 ? ...– 如果没有为action指定method,默认执行action中的 ...
2.与 struts1 对比,Struts2 的优点是什么? 对比,...在 struts.xml 中配 置 action 标签的 method ...将 调用 Action 里处理用户请求的处理方法;如果出现...
热门文档