Struts2 页面url请求如何找action
来源:互联网 发布:linux声卡参数设置 编辑:程序博客网 时间:2024/04/28 13:44
1.我们使用最原始的方法去查找action,不同注解。
struts.xml文件先配置
<!-- 新闻信息action -->
<action name="newsInfoAction" class="com.xxx.NewsInfoAction">
<result name="add">news/addNewsInfo.jsp</result>
<result name="update">news/editNewsInfo.jsp</result>
<result name="dataList">news/newsInfo.jsp</result>
</action>
action 默认执行的是NewsInfoAction中的excute方法。 http://localhost:8080/test/newsInfoAction.html 或者http://localhost:8080/test/newsInfoAction.action 看你如何在struts.xml文件中的配置(
<!-- 修改后缀 -->
那么有一个疑问,我们怎么访问NewsInfoAction中的其他方法呢?
访问指定方法
方式一:
http://localhost/struts2/simple/hello!say.action
可以调用hello这个action中的say方法
方式二:
http://localhost/struts2/simple/hello.action?method:say=xxx
可以调用say方法,在这里,参数的名称是:method:say,这是最主要的,struts2正是
根据参数的名称来决定该调用哪个方法,而不是参数的值,所以参数的值可以是任意的
方式三:
struts2的配置文件的action标签中存在一个method属性,用来指定访问特定的方法
<action name="hello" class="helloAction" method="say">
方式四:
<action name="hello_*" class="helloAction" method="{1}">
这样在页面中的action路径可写为hello_say.action就是访问say方法了。
2.如果struts2已经交给spring容器管理了,我们就可以通过注解来找action以及该action的方法了。(推荐使用这种方法,这样我们你就不用在struts.xml文件中再去配置各种action,可以给struts.xml减肥啦。)
url为 : http://localhost:8080/test/admin/editproduct.html?productInfoId=1 //参数可有可无
@SuppressWarnings("unchecked")
@Action(value = "/admin/editproduct", results = { @Result(name = "update", location = "product/editProductInfo.jsp") })
。。。。。。。
配置文件只需要配置注解即可:
<mvc:annotation-driven />
<context:annotation-config></context:annotation-config> 不能简写成<context:annotation-config/>
- Struts2 页面url请求如何找action
- Struts2 页面url请求如何找action
- struts2中如何去掉请求url中的.action
- struts2中采用url链接的action请求如何防止重复提交
- struts2指定欢迎页面为action请求
- struts2指定欢迎页面为action请求
- struts2点击action请求url重复命名空间
- struts2指定欢迎页面为action请求(转)
- 关于struts2在页面请求转发到action的问题
- Struts2如何查看工程下面所有action的URL
- struts2 action请求转发
- HttpURLConnection 请求struts2的action。如何拿到结果
- 页面发送action请求
- struts2 action 页面跳转
- [struts2]struts2 action 页面跳转
- struts2中action如何获取jsp页面参数
- struts2中action如何获取jsp页面参数
- URL页面请求分析
- POJ 1006 生理周期
- boost::algorithm
- 00docker安装和简介
- Problem C: 01字串
- VS2008/VS2010安装时提示VC++9.0 Runtime安装失败问题的解决方法
- Struts2 页面url请求如何找action
- 华为OJ题目(十八):图片整理
- Problem D: 最小节点(线性表)
- python 阶乘 + 计算阶乘末尾有几个零
- iOS开发扫盲篇
- 英文歌曲:God is a girl(上帝是女孩)
- Problem G: C语言习题 医生值班
- Android ListView 卡顿问题分析与解决方案
- HDU 3328 Flipper [模拟]