Struts2自定义Action,自定义方法,DMI(动态方法调用),路径问题
来源:互联网 发布:淘宝怎么买百度云账号 编辑:程序博客网 时间:2024/06/05 19:52
注意配置文件中的result JSP 必须加/(代表当前应用)
action类的编写:可以什么都不继承与实现,可以实现Action接口,可以继承ActionSupport,但推荐第三种
package struts.zyl;import com.opensymphony.xwork2.ActionSupport;public class IndexAction extends ActionSupport {public String add(){// TODO Auto-generated method stubreturn "success";}}
可以使用
http://localhost/struts2_action/path/userAdd
http://localhost/struts2_action/path/user!add(DMI动态方法调用,默认是关闭的,需要添加一句代码)
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
访问add.jsp
struts路径问题:
当在客户端输入http://localhost/struts2_action/path/index的时候,路径是根据struts2中的action路径而不是jsp的本地路径.
当用户想要从这个index.action中跳转回/index.jsp的时候..
通常会这样写
<a href="index.jsp">点我</a>
虽然就算这个jsp文件和index.jsp同一个目录,这样只会访问到本路径下的http://localhost/struts2_action/path/index.jsp
不能使用相对路径,
那么我们这样写呢?
<a href="/index.jsp">点我</a>
这样更不行,这样就返回到了http://localhost/index.jsp去了,连webapp都没有进入
我们只好这样写
<a href="/struts_action/index.jsp">点我</a>
这样倒是可以了,但是每次都要加上自己的项目名称未免太过麻烦
还好myeclipse帮我们自动解决了这个问题
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%>我们可以这样写
<a href="<%=basePath%>index.jsp">点我</a>
但是有更方便的:
<base href="<%=basePath%>">
这样我们每次跳转到index.jsp都是绝对路径了。
0 0
- Struts2自定义Action,自定义方法,DMI(动态方法调用),路径问题
- struts2 action DMI动态方法调用
- Struts2动态方法调用(DMI)小问题
- Struts2-动态方法调用(DMI)
- struts2动态方法调用(DMI)
- Struts2 DMI 动态方法调用
- Struts2 DMI动态方法调用
- Struts2-Action-4-系列问题(路径、调用Action的自定义方法、通配符)
- Struts2中DMI(动态方法调用)的一些问题
- Struts2中DMI(动态方法调用)的一些问题
- Struts2中DMI(动态方法调用)的一些问题
- Struts2中(动态方法调用)DMI的一些问题
- Struts2中DMI(动态方法调用)的一些问题
- Struts2中DMI(动态方法调用)的一些问题
- struts2——动态方法调用(dmi)!!!
- Struts2 ActionMethod 【DMI】(动态方法调用)
- Struts2的动态方法调用DMI
- struts2中的动态方法调用DMI
- WebView
- An intro to modern OpenGL. Chapter 2: Hello World: The Slideshow
- 黑马程序员_Java网络编程整理
- hdu-4724-How Long Do You Have to Draw-贪心
- 二进制和位运算
- Struts2自定义Action,自定义方法,DMI(动态方法调用),路径问题
- HDU 4597 Play Game
- 黑马程序员_Json学习笔记整理
- python基础教程_学习笔记20:标准库:一些最爱——os
- No Session found for current thread
- iosLearingDiary_CGContextAddArc
- android XMPP 开发总结(一)开发环境
- UVa 127 - "Accordian" Patience POJ 1214 链表题解
- fastjson 介绍