Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 주식이야기
- 스킨 스쿠버
- express for node.js
- ror실행
- nodejs express
- 디즈니씨
- 메일왕창보내는법
- iBatis
- 책이야기
- C/C++
- 나의 프로젝트
- php
- 베트남어
- php thumbnail
- 나의 취미
- node.js web framework
- Cross
- Lift
- rss
- 명사 뽑아내기
- ejb
- ajax
- 명사 추출기
- Node.js
- docker
- scala
- flex3
- 도커
- 명사 분석기
- Eclipse
Archives
- Today
- Total
nkdk의 세상
1장 스트럭쳐 예제 1번 본문
index.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<html><body>
<a href="index.do">로그온</a>
</body></html>
IndexAction.java
package example;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class IndexAction extends Action{
// execute 메서드를 만든다.(오버 라이딩 됨)
public ActionForward execute(
ActionMapping mapping, // 맵핑을 상속 받는다.
ActionForm form, // 폼을 상속 받는다.
HttpServletRequest request,
HttpServletResponse response) throws Exception{
request.setAttribute("title", "스트럿츠 만세");
return mapping.findForward("success");
}
}
// MyrequestProcess.java
package example;
import java.io.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class MyrequestProcess extends RequestProcessor{
protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
try {
request.setCharacterEncoding("EUC-KR");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// 이곳에서 전체적 영향을 받는 콘트롤러를 만든다.
System.out.println("Action 실행 보다 먼저 수행");
return true;
}
}
--------------------
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
<struts-config>
<action-mappings>
<action path="/index" type="example.IndexAction" >
<forward name="success" path="/success.jsp" />
</action>
</action-mappings>
<controller>
<set-property property="processorClass" value="example.MyrequestProcess" />
</controller>
</struts-config>
-------------------
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>str</display-name>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
-------
success.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<html><body>
결과는
<%=request.getAttribute("title") %>
<br>
${requestScope.title}
</body></html>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<html><body>
<a href="index.do">로그온</a>
</body></html>
IndexAction.java
package example;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class IndexAction extends Action{
// execute 메서드를 만든다.(오버 라이딩 됨)
public ActionForward execute(
ActionMapping mapping, // 맵핑을 상속 받는다.
ActionForm form, // 폼을 상속 받는다.
HttpServletRequest request,
HttpServletResponse response) throws Exception{
request.setAttribute("title", "스트럿츠 만세");
return mapping.findForward("success");
}
}
// MyrequestProcess.java
package example;
import java.io.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class MyrequestProcess extends RequestProcessor{
protected boolean processPreprocess(HttpServletRequest request, HttpServletResponse response) {
try {
request.setCharacterEncoding("EUC-KR");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
// 이곳에서 전체적 영향을 받는 콘트롤러를 만든다.
System.out.println("Action 실행 보다 먼저 수행");
return true;
}
}
--------------------
struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
<struts-config>
<action-mappings>
<action path="/index" type="example.IndexAction" >
<forward name="success" path="/success.jsp" />
</action>
</action-mappings>
<controller>
<set-property property="processorClass" value="example.MyrequestProcess" />
</controller>
</struts-config>
-------------------
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>str</display-name>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
-------
success.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<html><body>
결과는
<%=request.getAttribute("title") %>
<br>
${requestScope.title}
</body></html>