Struts2: the form has multiple submit submissions.

Source: Internet
Author: User

[Step 2] submit multiple form pages with submit or use URLs on JSP pages

  1. <S: Form Action = "useraction">
  2. <! --
  3. S: The method attribute in submit is the same as the method attribute in the Action tag in struts. XML (the method attribute specifies the method to be called ).
  4. In S: Submit, you can set multiple methods for an action. In struts. XML, you can set only one method in the Action tag.
  5. Of course, you can specify multiple actionnames (Action aliases) for an action in struts. xml ).
  6. Summary: An Action class can correspond to multiple action aliases. Each action alias corresponds to multiple method attributes (set using the S: Submit tag ).
  7. -->
  8. <S: Submit value = "Enter list page"Method = "list"/>
  9. <S: Submit value = "Enter the add page"Method = "add"/>
  10. </S: Form>
  1. <! -- Access through URL -->
  2. <! -- The request parameter is used to specify the action to be executed. The format is as follows: http: // localhost: 8080/contextpath/actionname! Method. Action -->
  3. Http: // localhost: 9090/tcts/user/useraction! List. Action
  4. Http: // localhost: 9090/tcts/user/useraction! Add. Action

[Step 2] Action class corresponding to Form

  1. Public class useraction extends actionsupport {
  2. Public String list (){
  3. System. out. println ("======================= this is list () method ==================== ");
  4. Return "list ";
  5. }
  6. Public String add (){
  7. System. out. println ("======================= this is add () method ==================== ");
  8. Return "add ";
  9. }
  10. Public String queryall (){
  11. Req = servletactioncontext. getrequest ();
  12. Ulist = userdao. queryall ();
  13. Req. getsession (). setattribute ("ulist", ulist );
  14. Return success;
  15. }
  16. }

Step 2: struts. xml

  1. <Struts>
  2. <Package name = "struts" extends = "struts-Default">
  3. <Action name = "useraction" class = "useraction">
  4. <Result name = "list" type = "redirectaction"> useraction_queryall </result>
  5. <Result name = "add">/user/user_insert.jsp </result>
  6. </Action>
  7. <Action name = "useraction_queryall" class = "useraction" method = "queryall">
  8. <Result>/user/user_list.jsp </result>
  9. </Action>
  10. </Package>
  11. </Struts>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.