๐ŸŒธ [SPRING] | WEB-INF , <param-name><param-value> , web.xml

0
post-thumbnail


๐Ÿ”น WEB-INF ํด๋”

  • ์ž์ฒด ๋ณด์•ˆ ํด๋”
  • ์™ธ๋ถ€์—์„œ ์ ˆ๋Œ€ ์ ‘๊ทผ ํ•  ์ˆ˜ ์—†์–ด์š”
  • ๊ทธ๋ž˜์„œ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๊ผญ ํ•„์š”ํ•œ css, js ํŒŒ์ผ์€ ์—ฌ๊ธฐ์— ์žˆ์œผ๋ฉด ์•ˆ๋ผ์š”. ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ฝ์„ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์— ์ฝ์„ ์ˆ˜ ์—†์–ด์š”.
  • jsp , html ํŒŒ์ผ๋„ ๋งˆ์ฐฌ๊ฐ€์ง€์ด๊ธฐ ๋•Œ๋ฌธ์— controller๋ฅผ ํ†ตํ•ด์„œ ๊ฐ„์ ‘์ ์œผ๋กœ ์ ‘๊ทผ์‹œ์ผœ์š”.

๐Ÿ”น WEBAPP ํด๋”


๐Ÿ”น <param-name><param-value>

	<init-param>
            <param-name>๋ฉค๋ฒ„ํ•„๋“œ๋ช…</param-name>
            <param-value>setting๋˜๋Š” ๊ฐ’</param-value>
        </init-param>

๐Ÿ”น web.xml

โœ… ๊ฒฝ๋กœ ์„ค์ •

๐Ÿ’จ

โœ… webappํด๋”

  • Web Resource Derectories์—ฌ๊ธฐ์„œ ์ด๋ ‡๊ฒŒ rootํด๋”๋กœ ์ €์žฅํ–ˆ๊ธฐ ๋•Œ๋ฌธ์—
  • ์™ธ๋ถ€์—์„œ ๋‹ค์ด๋ ‰ํŠธ๋กœ ์ ‘๊ทผ ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋œ๋‹ค.
  • ๊ทธ๋ž˜์„œ ๊ฒฝ๋กœ๋ฅผ ์น˜๋ฉด ์—ฌ๊ธฐ๋กœ ์ ‘๊ทผ๋˜๋Š” ๊ฒƒ์ด๋‹ค.
  • ๋‹ค๋ฅธ ํด๋”๋“ค ์˜ˆ๋ฅผ ๋“ค๋ฉด javaํด๋”๋Š” ์™ธ๋ถ€์—์„œ ์ ‘๊ทผ์„ ๋ชปํ•œ๋‹ค.


โœ… <web-app></web-app> ์•ˆ์—์„œ ์ž‘์„ฑ๋ผ์š”.


โœ… <servlet> , <servlet-mapping>

  • @WebServlet("/del3")
    public class BoardDelServlet3 extends HttpServlet { } ์ž‘์—…์„ ํ•˜๋Š” ๊ฑฐ์˜ˆ์š”.
    <servlet> 
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name> ๐Ÿ“
            <param-value>/WEB-INF/dispatcherServlet.xml</param-value> ๐Ÿ“
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
  • <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    : ์ด ์„œ๋ธ”๋ฆฟ์€ DispatcherServlet ์ด์˜ˆ์š”.
  • <load-on-startup>1</load-on-startup>
    : ์„œ๋ธ”๋ฆฟ ์ค‘ ์ œ์ผ ์ฒ˜์Œ ์‹œ์ž‘ํ•˜๋ผ๋Š” ์„ค์ •์ด์˜ˆ์š”.
  • <url-pattern>/</url-pattern>
  • / : ๋ชจ๋“ ์š”์ฒญ์€ ์ด DispatcherServlet์ด ๋ฐ›์•„์ฃผ๊ฒ ๋‹ค๋Š” ๋œป์ด์˜ˆ์š”.
  • ๋ชจ๋“  ์š”์ฒญ์„ , css , js , img ๋“ฑ์˜ ํŒŒ์ผ๋“ค ๊ฒฝ๋กœ๊นŒ์ง€๋„ controller์™€ ๋งคํ•‘์‹œํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ์ด ๋ถ€๋ถ„์€ dispatcherServlet.xml ์—์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ค˜์š”.

โœ… web.xml์— ๋Œ€ํ•œ ๋‚˜์˜ ๋Š๋‚Œ

๋ญ”๊ฐ€ DB์™€ servlet์„ ๋‹ด์•„๋†“์€ ๋Š๋‚Œ์ด์˜ˆ์š”. ๊ทธ๋ฆฌ๊ณ  ํ†ฐ์บฃ์ด ์ด๊ณณ์„ ๋จผ์ € ์ง€๋‚˜์น˜๊ณ  ํ”„๋กœ์ ํŠธ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋Š๋‚Œ์ด์˜ˆ์š”.


โ“ ๋ชจ๋ฅด๋Š” ๋ถ€๋ถ„

๐Ÿ”น ์ „์ฒด์ฝ”๋“œ

๐Ÿ‘† ๋งํฌ๋ฅผ ๋ˆ„๋ฅด๋ฉด ์†Œ์Šค๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <display-name>first</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet> <!--MVC2 ํŒจํ„ด์œผ๋กœ ๋งŒ๋“ค๊ธฐ ๋•Œ๋ฌธ์— servlet์€ ๋”ฑ ํ•˜๋‚˜๋งŒ ๋งŒ๋“ ๋‹ค.-->
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/dispatcherServlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!--@WebServlet("/del3")
    public class BoardDelServlet3 extends HttpServlet {} ์ž‘์—…์„ ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.-->
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern> <!-- / : ๋ชจ๋“ ์š”์ฒญ์€ ์ด servlet์ด ๋ฐ›์•„์ฃผ๊ฒ ๋‹ค.-->
    </servlet-mapping>

    <!--post๋ฐฉ์‹ ์ธ์ฝ”๋”ฉ-->
    <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>
    </filter>

    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern> <!--๋ชจ๋“  ์š”์ฒญ์ด ์ด ํ•„ํ„ฐ๋ฅผ ์ง€๋‚˜๊ฐ„๋‹ค.-->
    </filter-mapping>

</web-app>
profile
๋ช‡ ๋ฒˆ์„ ๋„˜์–ด์ ธ๋„ ์•ž์œผ๋กœ ๊ณ„์† ๋‚˜์•„๊ฐ€์ž

0๊ฐœ์˜ ๋Œ“๊ธ€