文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>struts模式匹配

struts模式匹配

时间:2011-02-15  来源:魔战

 <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");
 }
 
 
}

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载