[Step 2] submit multiple form pages with submit or use URLs on JSP pages
- <S: Form Action = "useraction">
- <! --
- 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 ).
- In S: Submit, you can set multiple methods for an action. In struts. XML, you can set only one method in the Action tag.
- Of course, you can specify multiple actionnames (Action aliases) for an action in struts. xml ).
- Summary: An Action class can correspond to multiple action aliases. Each action alias corresponds to multiple method attributes (set using the S: Submit tag ).
- -->
- <S: Submit value = "Enter list page"Method = "list"/>
- <S: Submit value = "Enter the add page"Method = "add"/>
- </S: Form>
- <! -- Access through URL -->
- <! -- The request parameter is used to specify the action to be executed. The format is as follows: http: // localhost: 8080/contextpath/actionname! Method. Action -->
- Http: // localhost: 9090/tcts/user/useraction! List. Action
- Http: // localhost: 9090/tcts/user/useraction! Add. Action
[Step 2] Action class corresponding to Form
- Public class useraction extends actionsupport {
- Public String list (){
- System. out. println ("======================= this is list () method ==================== ");
- Return "list ";
- }
- Public String add (){
- System. out. println ("======================= this is add () method ==================== ");
- Return "add ";
- }
- Public String queryall (){
- Req = servletactioncontext. getrequest ();
- Ulist = userdao. queryall ();
- Req. getsession (). setattribute ("ulist", ulist );
- Return success;
- }
- }
Step 2: struts. xml
- <Struts>
- <Package name = "struts" extends = "struts-Default">
- <Action name = "useraction" class = "useraction">
- <Result name = "list" type = "redirectaction"> useraction_queryall </result>
- <Result name = "add">/user/user_insert.jsp </result>
- </Action>
- <Action name = "useraction_queryall" class = "useraction" method = "queryall">
- <Result>/user/user_list.jsp </result>
- </Action>
- </Package>
- </Struts>