web developer

[spring] web.xml 본문

Framework/Spring [java]

[spring] web.xml

trueman 2021. 12. 23. 00:26
728x90
728x90

web.xml

웹에 관련한 설정을 모아둔 파일이다. 설정파일의 경로를 바꿔놓았으니 web.xml에서 변경된 경로로 작성해준다. 쉽게 resources 폴더로 들어가는 방법은 class:/를 이용한다.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 
    <!-- DB설정 등 비즈니스 로직 설정을 관리할 xml 설정 경로 지정 (root-context.xml) -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <!-- 경로 변경 (기존경로 : /WEB-INF/spring/root-context.xml -->
        <param-value>classpath:/spring/mvc-config.xml</param-value>
    </context-param>
    
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
    <!-- Dispatcher Servlet 설정 xml파일 경로 지정 (servlet-context.xml) -->
    <servlet>
        <!-- 서블릿 클래스의 이름은 appServlet이다. -->
        <servlet-name>appServlet</servlet-name>
        <!-- 클래스의 위치는 다음과 같다. -->
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!-- 초기 파라미터 (초기값) 이름과 값을 다음과 같이 지정하겠다. -->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <!-- 경로 변경 (기존 경로 : /WEB-INF/spring/appServlet/servlet-context.xml -->
            <param-value>classpath:/spring/servlet-config.xml</param-value>
        </init-param>
        <!-- 1 : 누구보다 먼저 호출하겠다. -->
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- 서블릿 URL Mapping 설정 -->
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <!-- /로 시작하는 url이 들어가면 서블릿을 작동하겠다. 모든 요청이 들어가야하기 떄문에 /로 작성 -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    <!-- 한글 처리 코드 -->
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    
    <!-- 위에 지정한 encodingFilter이름을 모든 패턴에 적용 -->
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 
</web-app>

출처 : https://yeahajeong.tistory.com/49?category=957804 

 

[SpringMVC] 초기 설정 - servlet-context.xml

servlservlet-context.xml 앞에서 servlet-context.xml 파일의 이름을 servlet-config.xml로 변경하였다. 이 파일은 DispacherServlet의 기반 설정을 기록하는 파일이다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16..

yeahajeong.tistory.com

 

728x90
728x90
Comments