3. TestAction.java
앞의 test.xml의 액션태그에서 본바와 같이 한 액션에서 /test/메서드명.action
을 호출하면 해당 메서드로 이동합니다.
-------------------------------------------------------
--------------- TestAction ------------------------------
-------------------------------------------------------
package test;
import javax.servlet.http.*;
import org.apache.struts2.interceptor.*;
import com.opensymphony.xwork2.*;
/**
* Base Action class for the Tutorial package.
*/
public class TestAction extends ActionSupport implements ServletRequestAware {
private HttpServletRequest request;
/**
*
*/
private static final long serialVersionUID = 1L;
public String test1() throws Exception {
System.out.println("/test/test1.action start");
// request를 가져온다.
String names = request.getParameter("name");
System.out.println("name = " + names);
System.out.println("/test/test.action end");
return "successTest";
}
public String test2() throws Exception {
System.out.println("/test/test2.action start");
// request를 가져온다.
String names = request.getParameter("name");
System.out.println("name = " + names);
System.out.println("/test/test.action end");
return "successTest";
}
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
}
4. test1.jsp
시작페이지입니다.
-------------------------------------------------------
--------------- test1.jsp ------------------------------
-------------------------------------------------------
<%@ page contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<html>
<head>
<title>Test</title>
</head>
<body>
<form name="test1Form" method="post" action="/test/test1.action">
test1()메서드를 거치는 경우
name :
<input type="text" name="name">
<input type="submit" value="입력">
</form>
<form name="test2Form" method="post" action="/test/test2.action">
test2()메서드를 거치는 경우
name :
<input type="text" name="name">
<input type="submit" value="입력">
</form>
</body>
</html>
5. test2.jsp
액션 클래스를 걸쳐 포워딩되는 페이지입니다.
-------------------------------------------------------
--------------- test2.jsp ------------------------------
-------------------------------------------------------
<%@ page contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%
String name = request.getParameter("name");
%>
<html>
<head>
<title>Test</title>
</head>
<body>
Hello! <%=name%>!!!
</body>
</html>
===========================================================
마무리.
struts1에 비해 사용법이 한결 가벼워졌다는 느낌이 들었습니다.
제공하는 jsp태그는 소스를 간단히 하기 위해 제거하였습니다.
관심이 있으신 분은 jsp태그도 사용해 보신다면 더 강해진 기능을
보실 수가 있을 겁니다.
앞의 test.xml의 액션태그에서 본바와 같이 한 액션에서 /test/메서드명.action
을 호출하면 해당 메서드로 이동합니다.
-------------------------------------------------------
--------------- TestAction ------------------------------
-------------------------------------------------------
package test;
import javax.servlet.http.*;
import org.apache.struts2.interceptor.*;
import com.opensymphony.xwork2.*;
/**
* Base Action class for the Tutorial package.
*/
public class TestAction extends ActionSupport implements ServletRequestAware {
private HttpServletRequest request;
/**
*
*/
private static final long serialVersionUID = 1L;
public String test1() throws Exception {
System.out.println("/test/test1.action start");
// request를 가져온다.
String names = request.getParameter("name");
System.out.println("name = " + names);
System.out.println("/test/test.action end");
return "successTest";
}
public String test2() throws Exception {
System.out.println("/test/test2.action start");
// request를 가져온다.
String names = request.getParameter("name");
System.out.println("name = " + names);
System.out.println("/test/test.action end");
return "successTest";
}
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
}
4. test1.jsp
시작페이지입니다.
-------------------------------------------------------
--------------- test1.jsp ------------------------------
-------------------------------------------------------
<%@ page contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<html>
<head>
<title>Test</title>
</head>
<body>
<form name="test1Form" method="post" action="/test/test1.action">
test1()메서드를 거치는 경우
name :
<input type="text" name="name">
<input type="submit" value="입력">
</form>
<form name="test2Form" method="post" action="/test/test2.action">
test2()메서드를 거치는 경우
name :
<input type="text" name="name">
<input type="submit" value="입력">
</form>
</body>
</html>
5. test2.jsp
액션 클래스를 걸쳐 포워딩되는 페이지입니다.
-------------------------------------------------------
--------------- test2.jsp ------------------------------
-------------------------------------------------------
<%@ page contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%
String name = request.getParameter("name");
%>
<html>
<head>
<title>Test</title>
</head>
<body>
Hello! <%=name%>!!!
</body>
</html>
===========================================================
마무리.
struts1에 비해 사용법이 한결 가벼워졌다는 느낌이 들었습니다.
제공하는 jsp태그는 소스를 간단히 하기 위해 제거하였습니다.
관심이 있으신 분은 jsp태그도 사용해 보신다면 더 강해진 기능을
보실 수가 있을 겁니다.
![]() | ![]() ![]() | 12-27 | 2878 | |
![]() | ![]() ![]() | 12-11 | 2098 | |
53 | ![]() ![]() | 03-15 | 1955 | |
52 | ![]() ![]() | 01-31 | 2093 | |
51 | ![]() ![]() | 01-31 | 3063 | |
50 | ![]() ![]() | 01-31 | 1617 | |
49 | ![]() ![]() | 01-19 | 1941 | |
48 | ![]() ![]() | 01-11 | 1808 | |
47 | ![]() ![]() | 01-03 | 2414 | |
46 | ![]() ![]() | 12-27 | 2878 | |
45 | ![]() ![]() | 12-19 | 2021 | |
44 | ![]() ![]() | 12-14 | 1988 | |
43 | ![]() ![]() | 12-11 | 2098 | |
42 | ![]() ![]() | 12-09 | 1632 | |
41 | ![]() ![]() | 12-01 | 1853 | |
40 | ![]() ![]() | 12-01 | 2098 | |
39 | ![]() ![]() | 12-01 | 1505 |
댓글 없음:
댓글 쓰기