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

  • 相关阅读:
    第一章 初识shiro
    LDAP概念
    css定位
    css随笔1
    自己动手实现信息检索系统
    IntelliJ IDEA和pycharm注册码
    俄罗斯农夫算法
    [NOIP2013]转圈游戏
    [codevs1287]矩阵乘法
    [洛谷1314]无序字母对
  • 原文地址:https://www.cnblogs.com/jinzhengquan/p/1955233.html
Copyright © 2020-2023  润新知