假设前端代码:

 <a href="user/add.do?command=add">添加用户</a><br>
 <a href="user/del.do?command=del">删除用户</a><br>
 <a href="user/modify.do?command=modify">修改用户</a><br>

模式匹配的过程:

假设用户请求<a href="user/add.do?command=add">添加用户</a><br>
那么会根据请求地址转到相应action的配置中,假设Action配置为:

配置代码:

 <action path="/user/*"
    type="com.bjsxt.struts.UserAction"
    parameter="command" 
  >
   <!--
   <forward name="success" path="/user/{1}_success.jsp"/>
    -->
    <forward name="success" path="/{0}_success.jsp"/>
  </action>

那么在此*对应的值为add,所以通配符{0}的值为add。同理也可在name中使用通配符

 <forward name="{0}_success" path="/{0}_success.jsp"/>

Action代码:

public class UserAction extends DispatchAction {

 public ActionForward add(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  //return mapping.findForward("add_success");
  return mapping.findForward("success");
 }

 public ActionForward del(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  //return mapping.findForward("del_success");
  return mapping.findForward("success");
 }

 public ActionForward modify(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  //return mapping.findForward("modify_success");
  return mapping.findForward("success");
 }
 
 
}

posted on 2011-02-15 15:08  魔战  阅读(293)  评论(0编辑  收藏  举报