SSH - Struts 2 탄: 하나의 Form 제출 2 개의 Action
7941 단어 struts
1. 여러 submit 폼 페이지 또는 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> 상기 코드 에 따라 성공 사례 가 나 오지 않 았 습 니 다.각종 대 신의 지 도 를 구하 다.