[struts2] struts2 환경설정

수진·2023년 2월 11일
0

환경설정하기

목록 보기
6/8

1. 라이브러리에 파일 추가하기

lib에는 총 22개의 jar파일이 들어가 있어야 한다.
struts2에서 web구동에 필요한 파일 + ibatis + log4j + ojbdc +jstl

2. 필요한 파일들 옮겨놓기

  1. com.util(FileManager.java, MyUtil.java)
  2. com.util.dao(CommonDAO.java, CommonDAOImpl.java)
  3. com.util.sqlMap(SqlMapConfig.java, sqlMapConfig.xml, temp_sqlMap.xml)
  4. log4j.properties -> src폴더에 옮겨놓기

3. web.xml세팅하기

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>struts2</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <!-- Struts2 환경 셋팅 -->
  <filter>
  	<filter-name>struts2</filter-name>
  	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  
  <filter-mapping>
  	<filter-name>struts2</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
  
</web-app>

4. WEB-INF에 파일 만들기

  • WEB-INF에 classes폴더 만들기

struts.properties파일

struts.i18n.encoding=UTF-8
struts.action.extention=action
struts.multipart.saveDir=c:\\temp
struts.configuration.files=struts-default.xml,struts.xml
  • struts.i18n.encoding=UTF-8 : struts의 한글 인코딩 설정을 해주는 것
    com.filter의 CharEncoding.java가 필요없어진다.
  • struts.action.extention=action : .action의 주소가 오
  • struts.multipart.saveDir=c:\\temp:
  • struts.configuration.files=struts-default.xml,struts.xml : struts-default.xml파일을 읽은 다음에 struts.xml(내가 생성한 파일)을 읽어들인다.

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>
 
<package name="" extends="struts-default" namespace="">
	<global-results>
		<result name="error">/exception/error.jsp</result>
	</global-results>
</package> 

	<include file="struts-test.xml"/>
	<include file="struts-board.xml"/>
 
</struts>
  • 사용할 xml파일들을 include태그로 추가해준다.

struts-temp.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>

<package name="" extends="struts-default" namespace="">


</package>

</struts>
  • 필요에 따라서 파일을 복사해서 사용하면 된다.

이렇게 하면 struts2를 사용할 수 있는 기본 세팅은 끝~!

0개의 댓글