Struts2学习之旅(2)
来源:互联网 发布:去人声软件 编辑:程序博客网 时间:2024/06/05 11:30
Struts2学习之旅(2)—-动态方法调用(通配符)
HelloWorldAction.java
package com.chb.action;import java.util.Map;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class HelloworldAction extends ActionSupport { @Override public String execute() throws Exception { //首先获取ActionContext对象 ActionContext actionContext = ActionContext.getContext(); //获取session的Map模拟对象 Map session = actionContext.getSession(); //获取applicationContext的Map模拟对象 Map applicationContext = actionContext.getApplication(); applicationContext.put("app", "test"); //返回指定的视图,跳到那个界面 return SUCCESS; } //动态方法的调用, 是为了解决一个Action对应多个请求,以免Action过多。 public String add() { return "add"; } public String update() { return "update"; }}
使用动态方法调用, struts.xml配置
使用通配符, 不用添加更多的<action>
通过向method中添加通过符{1}
相对应的<result>中添加通配符{1};
在请求时
url:
update方法:
http://localhost:8080/Helloworld/helloworld_update.action
add方法
http://localhost:8080/Helloworld/helloworld_add.action
<!-- 使用通配符 --> <package name="default" namespace="/" extends="struts-default"> <action name="helloworld_*" method="{1}" class="com.chb.action.HelloworldAction"> <result>/result.jsp</result> <result name="add">/{1}.jsp</result> <result name="update">/{1}.jsp</result> </action> </package>
0 0
- Struts2学习之旅(2)
- struts2 学习之旅
- Struts2学习之旅(3)
- Struts2学习之旅(4)
- Struts2学习之旅(5)
- Struts2学习之旅(6)
- Struts2学习笔记(2)之Result
- Struts2之struts2学习总结
- Struts2学习之Struts2简介
- SSH框架学习之Struts2(2):接收参数
- Struts2学习笔记(12)-----Struts2之动态方法调用
- (Struts2学习篇) Struts2数据校验之二
- struts2学习笔记之五(struts2的处理过程)
- J2EE系列之Struts2学习笔记(十八)--Struts2国际化
- Struts2系统学习(2)Struts2-HelloWorld
- Struts2学习笔记(一)之 值栈
- struts2源码学习之初始化(一)
- struts2源码学习之初始化(二)
- AVPlayer自定制视频播放器(1)——视频播放器基本实现
- Sql中Insert添加语句如何不重复
- Cf Edu 15 C 城市与信号塔[二分]
- 洛谷 P2530 [SHOI2001]化工厂装箱员
- leetcode #4: Median of Two Sorted Arrays
- Struts2学习之旅(2)
- Java容器五:Vector
- iOS简单使用description方法(参考大神博客+自己想法)
- C++之引用
- 淘宝API示例
- [基础算法]递归二分算法
- EditText焦点问题 Android开发之ListView+EditText-要命的焦点和软键盘问题解决办法
- 整数的各位数之和与指数的递归求法
- 51. magento 手动创建订单