note

스트럿츠2 설치&셋팅 본문

JSP/Struts2

스트럿츠2 설치&셋팅

투한 2012. 2. 20. 16:51







2.0.14 백업





 









기본 설정








































프로젝트 생성


















생성됨






쓸모 없는 파일들 지우기



















필수 요소


web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" 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>Struts2Main</display-name>

	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
		<init-param>
			<param-name>struts.i18n.encoding</param-name>
			<param-value>utf-8</param-value>
		</init-param>
	</filter>

	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
	</welcome-file-list>

</web-app>




package -> tutorial
class -> HelloWorld



기본 동작 확인을 위한 생성



 
  HelloWorld.java
package tutorial;

import com.opensymphony.xwork2.Action;

public class HelloWorld implements Action{
	private String message;
	
	public String getMessage(){
		return message;
	}
	@Override
	public String execute() throws Exception {
		
		message = "Hello, World";
		
		return SUCCESS;
	}
}

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

    <!-- 1.기본연결 -->
    <package name="tutorial" extends="struts-default">
    	<action name="helloWorld" class="tutorial.HelloWorld">
    		<result name="success">/helloWorld.jsp</result>
    	</action>
    </package>

</struts>







인코딩 방식 UTF-8로 바꾸기












jsp -> action 변경