struts2中action的路径问题以及在MyEclipse8.5中的说明(通配符等等)
来源:互联网 发布:linux shell删除文件 编辑:程序博客网 时间:2024/06/05 03:42
//IndexAction。java
public class IndexAction extends ActionSupport {
public String execute() {
return "success";
}
}
//对应的struts.xml
<package name="front" extends="struts-default" namespace="/">
<action name="index" class="front.action.IndexAction" method="...">
<result name="success">/ActionIntroduction.jsp</result>
</action>
</package>
Action执行的时候并不一定要执行execute方法
可以在配置文件中配置Action的时候用method=来指定执行哪个方法
也可以在url地址中动态指定(动态方法调用DMI)(推荐)
DMI(动态方法调用)方式:
<package name="user" extends="struts-default" namespace="/user">
<action name="user" class="user.action.UserAction">
<result>/user_add_success.jsp</result>
</action>
</package>
链接写法:<a href="user/user!add">添加用户</a>
使用通配符配置action方式:
<package name="actions" extends="struts-default" namespace="/actions">
<action name="Student*" class="action.StudentAction" method="{1}">
<result>/Student{1}_success.jsp</result>
</action>
<action name="*_*" class="action.{1}Action" method="{2}">
<result>/{1}_{2}_success.jsp</result>
</action>
</package> 其中"{1}”表示第1个*号,"{2}”表示第2个*号,以此类推
2) 路径问题
struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径
虽然可以用redirect方式解决,但redirect方式并非必要。
解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextRoot方式来拿到webapp的路径)
或者使用myeclipse经常用的,指定basePath
解决办法:
加入:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+
request.getServerName()+":"+request.getServerPort()+path+"/";
%>
在<head>标签后加入
<base href="<%=basePath%>" />
这样,这个页面中所的连接,jsp都会帮忙加上:http://localhost:8080/appricationName/ (类似这样的东西)
不过我在实际敲的过程中发现;在MyEclipse8.5中,struts2-2.1.6,struts2-2.2.1可以不用绝对路径而正常跳转,估计是struts版本的一个改进吧.也不知道是不是MyEclipse8.5开发环境的问题.
最后我发现是因为MyEclipse8.5已经生成了解决办法的脚本,所以不用再加这些脚本了。如果是自己建的页面没有这些脚本添加即可.
- struts2中action的路径问题以及在MyEclipse8.5中的说明(通配符等等)
- struts2的通配符使用以及路径问题浅析
- struts2中action有无通配符的优先级问题
- Struts2-Action-4-系列问题(路径、调用Action的自定义方法、通配符)
- 2、struts2开发action 的三种方法以及通配符、路径匹配原则、常量
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射 (
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- Struts2中Action通配符的配置
- struts中的action和Action类以及struts2中如何在Action类中获得servlet api的域对象
- Struts2中的通配符和常量的说明
- 在struts1.2中的action路径内使用通配符
- struts2的action方法匹配以及通配符的使用
- struts2的action方法匹配以及通配符的使用
- struts2的action方法匹配以及通配符的使用
- 静态链接
- 有关STL中的容器和MFC的集合类型构造函数区别的一点思考
- ez Content action handlers
- mysql c api 列表(转贴自http://blog.csdn.net/loveu131/archive/2006/07/26/982629.aspx)
- 公司间交易退货配置问题
- struts2中action的路径问题以及在MyEclipse8.5中的说明(通配符等等)
- 2.给自己的生活树立目标,别浪费在没有意义的人身上
- 解析器小结
- handle_one_connection()
- FileWriter(String) 写文件换行的方法。
- 如何用delphi开发斗地主记牌器
- 摩斯码装换程序
- 创建和使用动态链接库 (C++)C#调用
- use a Content action handlers to add comment for node