Struts2 Framework 환경설정
http://struts.apache.org 에서 struts-2.1.8.1-lib.zip을 다운로드 받습니다.
압축을 풀고 라이브러리를 웹어플리케이션 /WEB-INF/lib/ 디렉토리 아래에 복사합니다.
필수 라이브러리는 다음과 같습니다.
-
struts2-core-2.1.8.1.jar
-
xwork-core-2.1.6.jar
-
ognl-2.7.3.jar
-
commons-logging-1.0.4
-
freemarker-2.3.15
Struts2 Framework 라이브러리
라이브러리(jar파일) |
설명 |
struts2-core-2.0.X.jar |
스트럿츠2의 핵심 라이브러리이다. |
xwork-2.0.5.jar |
스트럿츠2의 새로운 점 중 가장 큰 부분이 Webwork (=Xwork) 와 통합 되었는다는 것이다. xwork가 주가 되고 struts가 뒷받침 해주는 형식으로 작동한다. |
ognl-2.6.11.jar |
Object Graph Navigation Language라고 한다. struts2를 위한 EL(Expression Language)이다. JSP 2.1 스펙에 포함된 EL과 매우 비슷하다. |
commons-logging-1.0.4.jar |
log4j와 같은 로깅을 위한 라이브러리이다. |
freemarker-2.3.8.jar |
UI 태그 템플릿을 위한 라이브러리이다 |
Struts2 Framework 환경설정 파일
web.xml
스트럿츠2의 컨트롤러인 FilterDispatcher는 액션을 실행하기 위한 환경을 구축하기에 스트럿츠 프레임워크로 들어오는 모든 요청에 대해서 최초의 진입점이org.apache.struts2.dispatcher.FilterDispatcher가 되도록 해야 한다.
-
Deployment Descriptor
-
FilterDispater를 등록해야 한다.
WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>basic</display-name>
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
</web-app> |
struts-default.xml
struts2-core-2.1.8.1.jar의 루트에 struts- default.xml 파일이 존재한다.
기본적인 설정내용을 포함하고 있다.
ResultType, Interceptor, Intercepter- stack 등
struts-default.xml
… <struts> <bean class="com.opensymphony.xwork2.ObjectFactory" name="xwork" /> <bean type="com.opensymphony.xwork2.ObjectFactory" name="struts" class="org.apache.struts2.impl.StrutsObjectFactory" />
<bean type="com.opensymphony.xwork2.ActionProxyFactory" name="xwork" class="com.opensymphony.xwork2.DefaultActionProxyFactory"/> <bean type="com.opensymphony.xwork2.ActionProxyFactory" name="struts" class="org.apache.struts2.impl.StrutsActionProxyFactory"/> … <package name="struts-default" abstract="true"> <result-types> <result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/> <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/> … </result-types>
<interceptors> <interceptor name="alias" class="com.opensymphony.xwork2.interceptor.AliasInterceptor"/> <interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/> <interceptor name="chain" class="com.opensymphony.xwork2.interceptor.ChainingInterceptor"/> … </interceptors>
… <interceptor-stack name="defaultStack"> <interceptor-ref name="exception"/> <interceptor-ref name="alias"/> <interceptor-ref name="servletConfig"/> <interceptor-ref name="prepare"/> … </interceptor-stack> … <default-interceptor-ref name="defaultStack"/> </package>
</struts> |
struts.xml
클래스패스 루트에 위치해야 한다.
<package> 요소를 사용하여 액션, 리절트, 인터셉터에 대한 설정을 패키지 단위로 묶는다.
struts-default 패키지는 스트럿츠2에서는 제공해 주는 디폴트 설정 파일인 struts-default.xml에 정의되어 있다.
struts-default 패키지는 스트럿츠2로 웹 애플리케이션을 개발하는데 필요한 리절트 타입이나 인터셉터 등을 미리 정의해 두었기에 이를 상속받으면 기본적으로 제공되는 기능들을 일일이 정의하지 않고도 사용할 수 있다는 장점이 있다.
-
프레임워크의 제어를 설정하는 파일.
-
액션, 인터셉터, 리절트 등을 설정한다.
WEB-INF/classes/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> <constant name="struts.devMode" value="true"/> <package name="basic" extends="struts-default">
<action name="hello*" class="struts2.hello.HelloAction{1}"> <result name="success">/hello.jsp</result> </action>
</package> </struts> |
struts.properties
프레임워크의 동작방식을 설정하는 파일.
-
클래스패스 루트에 위치해야 한다.
-
프레임워크의 구동방식에 대한 설정을 한다.
-
default.properties에 설정된 기본값을 재정의해서 사용할 수 있다.
-
설정하는 모든 프로퍼티들은 struts.xml에 상수로도 설정가능하다.
WEB-INF/classes/struts.properties
struts.devMode=true struts.custom.i18n.resources=applicationMessages |
또는 다음과 같이 설정도 가능하다.
WEB-INF/classes/struts.xml
<struts> <constant name="struts.devMode" value="true" /> <constant name="struts.custom.i18n.resources" value="applicationMessages" /> </struts> |
'개발자 센터 > Struts2' 카테고리의 다른 글
struts2에서 세션(session) 사용하기 (0) | 2009.12.14 |
---|---|
Struts2 문자열 출력 예제 (0) | 2009.12.11 |
Struts2 Action : 액션 (0) | 2009.12.11 |
Struts2 Framework 아키텍처 (0) | 2009.12.11 |
Struts2 Framework의 특징 (0) | 2009.12.11 |