• SSH-Struts第二弹:一个Form提交两个Action


    根据CSDN中的博客:http://blog.csdn.net/forwayfarer/article/details/3030259进行学习。

    1、多个submit的Form表单页面 or 在jsp页面中使用URL进行提交

    <s:form action="UserAction">    
    <!-- s:submit中的method属性和struts.xml中action标签中的method属性一致(method属性指定了要调用的方法)。 在s:submit中可以为一个action设置多个method,而在struts.xml中action标签中只能设置一个method。 当然,在struts.xml中可以为一个action指定多个actionName(action别名)。 总结:一个Action类,可以对应多个action别名,每个action别名对应多个method属性(通过s:submit标签设置)。 --> <s:submit value="进入List页面" method="list" /> <s:submit value="进入Add页面" method="add" />
    <!-- 通过URL访问 -->
    <!-- 通过请求参数来指定要执行的动作,格式如下:http://localhost:8080/contextPath/actionName!method.action -->
    http://localhost:9090/TCTS/user/UserAction!list.action
    http://localhost:9090/TCTS/user/UserAction!add.action

    2、Form表单对应的Action类

     1 public class UserAction extends ActionSupport {
     2     public String list() {
     3         System.out.println("================这是list()方法================");
     4         return "list";
     5     }
     6     
     7     public String add() {
     8         System.out.println("================这是add()方法================");
     9         return "add";
    10     }
    11     
    12     public String queryAll() {
    13         req = ServletActionContext.getRequest();
    14         uList = userDAO.queryAll();
    15         req.getSession().setAttribute("uList", uList);
    16         return SUCCESS;
    17     }
    18 }

    3、Struts.xml

     1 <struts>
     2     <package name="struts" extends="struts-default">
     3     
     4         <action name="UserAction" class="userAction">
     5             <result name="list" type="redirectAction">UserAction_queryAll</result>
     6             <result name="add">/user/user_insert.jsp</result>
     7         </action>
     8         
     9         <action name="UserAction_queryAll" class="userAction" method="queryAll">
    10             <result>/user/user_list.jsp</result>
    11         </action>
    12         
    13     </package>
    14 </struts>

    根据以上代码,没有做出成功的案例。求各种大神指教。

  • 相关阅读:
    HTML5 Canvas Overview
    HTML5 Canvas Tutorial
    CSS Inheritance
    Get Foreign Keys
    Spring + JdbcTemplate + JdbcDaoSupport examples
    Spring + JDBC example
    Get Primary Key Column From A Table
    python学习第19天之目录规范和常用模块之time
    python学习的第十八天模块之包、相对搜索路径和绝对搜索路径
    python学习的第十七天 模块、内置函数
  • 原文地址:https://www.cnblogs.com/Candies/p/3606575.html
Copyright © 2020-2023  润新知