struts配置中的路径与模式匹配
来源:互联网 发布:翰文网络计划注册码 编辑:程序博客网 时间:2024/04/28 11:09
<!--[if !supportLists]-->³ <!--[endif]-->struts配置中的action,有一个path属性,它表明请求的URI
<!--[if !supportLists]-->³ <!--[endif]-->一般情况下,我们需要在配置文件中明确指定某个特定的URI,如path=“/user/add”
<!--[if !supportLists]-->³ <!--[endif]-->在一些大型应用中,如果能够制定一套严格的路径及其操作规范的话,我们可以利用path的路径模式匹配功能,来简化struts配置文件繁琐的编写工作量
<!--[if !supportLists]-->³ <!--[endif]-->假设有如下规范:
<!--[if !supportLists]-->³ <!--[endif]-->对user对象的所有处理Action,均需要以如下的路径进行访问:
<!--[if !supportLists]-->³ <!--[endif]-->/user/add.do – 处理用户添加的有关操作
<!--[if !supportLists]-->³ <!--[endif]-->/user/delete.do – 处理用户删除的有关操作
<!--[if !supportLists]-->³ <!--[endif]-->/user/update.do – 处理用户更新的有关操作
<!--[if !supportLists]-->³ <!--[endif]-->…
<!--[if !supportLists]-->³ <!--[endif]-->所有操作(Action)对应的JSP如下:
<!--[if !supportLists]-->³ <!--[endif]-->所有操作成功(失败)之后的转向页面,有如下命名规范:
<!--[if !supportLists]-->³ <!--[endif]-->/user/add.do -> /user/add_success.jsp或/user/add_error.jsp
<!--[if !supportLists]-->³ <!--[endif]-->/user/delete.do -> /user/delete_success.jsp或/user/delete_error.jsp
<!--[if !supportLists]-->³ <!--[endif]-->…
<!--[if !supportLists]-->³ <!--[endif]-->所有操作的输入界面有如下命名规范:
<!--[if !supportLists]-->³ <!--[endif]-->添加操作 -> /user/add_input.jsp
<!--[if !supportLists]-->³ <!--[endif]-->更新操作 -> /user/update_input.jsp
<!--[if !supportLists]-->³ <!--[endif]-->…
Action配置示例:
<action
path="/user/*"
type="com.bjsxt.struts.web.actions.UserAction"
name="userForm"
parameter="method"
>
<forward name="index" path="/user/index.jsp"/>
<forward name="success" path="/user/{1}_success.jsp"/>
<forward name="error" path="/user/{1}_error.jsp"/>
<forward name="input" path="/user/{1}_input.jsp"/>
</action>
解释如下:
<!--[if !supportLists]-->³ <!--[endif]-->所有的/user/*.do请求,都将由UserAction这个类来处理,UserAction类继承DispatchAction,它将根据传入的method参数的值,来分发到不同的方法来进行处理
<!--[if !supportLists]-->³ <!--[endif]-->在UserAction类中的任何一个方法,都可以返回index/success/error/input等名称的ActionForward
<!--[if !supportLists]-->³ <!--[endif]-->根据请求路径的不同,即使调用相同的返回代码,但其转向也将不同,如:
<!--[if !supportLists]-->² <!--[endif]-->/user/add.do?method=add请求,将被转发给UserAction类的add方法处理,假设它用mapping.findForward(“success”);来返回成功页面,这将转向的实际JSP页面是:/user/add_success.jsp
<!--[if !supportLists]-->² <!--[endif]-->而/user/delete.do?method=delete请求,将被转发给UserAction类的delete方法处理,假设它用mapping.findForward(“success”);来返回到删除成功页面,这将转向的实际JSP页面是:/user/delete_success.jsp,所以,不同URI请求的相同名称的返回页面将是不同的。
<!--[if !supportLists]-->² <!--[endif]-->而/user/index.do请求(或者任何一个其它请求,如/user/abcd.do或/user/test.do),都因为没有传递method参数,而触发调用UserAction的unspecified方法
- struts配置中的路径与模式匹配
- struts配置中的路径与模式匹配
- Struts2 通过配置struts.xml中的actio标签name属性值来与请求路径映射
- struts模式匹配
- Struts模式匹配
- struts中路径匹配原则
- JavaScript中的模式匹配与正则表达式
- Erlang中的模块与模式匹配
- 关于Struts.xml文件中的配置(路径问题)
- struts中的路径问题
- web中的路径匹配
- struts转发与路径
- Struts.xml中Action的method与路径的三种匹配方法
- Struts.xml中Action的method与路径的三种匹配方法
- Struts.xml中Action的method与路径的三种匹配方法
- Struts.xml中Action的method与路径的三种匹配方法
- 路径和模式匹配.avi
- Filter路径的匹配模式
- 如何通过ftp对比多个机器的文件差别
- I changed to the service---github instead
- 类构造器包含一个本类参数的代码使用
- Struts2+hibernate+spring 配置文件中scope="prototype"的作用
- struts模式匹配
- struts配置中的路径与模式匹配
- 关于多维数组的“不形象”理解
- 域名分类详细介绍
- 游客进场
- 选择ARM处理器,ARM7还是Cortex-M3
- 假期过去了
- utf-8,gbk,gb2312的区别
- JavaScript程序编码规范中文版
- 中国IP发展之面面观