zoukankan      html  css  js  c++  java
  • struts模式匹配

    假设前端代码:

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

  • 相关阅读:
    [Poi2000]病毒
    [Zjoi2015]诸神眷顾的幻想乡
    P1663 山
    P1837 单人纸牌
    P6584 重拳出击
    CF460C Present
    10.5 学习笔记
    多项式学习笔记(一) FFT
    NOIP 2020 游记
    uva 经典习题选做(dp专项)
  • 原文地址:https://www.cnblogs.com/jinzhengquan/p/1955233.html
Copyright © 2011-2022 走看看