|
Spring frameworkÀÌ À¯ÇàÇϰí REST Style URLÀÌ À¯ÇàÇÏ¸é¼ Á÷¸éÇÏ´Â ¹®Á¦°¡ Çϳª ÀÖ´Ù.
´ÙÀ½°ú °°Àº url·Î ¼ºñ½º¸¦ ÇÑ´Ù°í °¡Á¤Çغ¸ÀÚ. /article /article/1 /article/add
À½ °¥²ûÇÑ URLÀÌ´Ù. ¤»
±×·¯¸é web.xml¿¡ ´ÙÀ½°ú °°ÀÌ url-patternÀ» ¼³Á¤ÇÏ°Ô µÈ´Ù.
<servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
REST StyleÀÇ urlÀ» °¡Á®¾ß ÇÔÀ¸·Î url-patternÀº /* ó·³ °É¾î¾ß ÇÑ´Ù. .do¿Í °°Àº È®ÀåÀÚ¸¦ °¡Á®¼´Â ¾ÈµÈ´Ù. <-- Ã̽º·¯... ¤»¤»
¾Æ ¹°·Ð viewResolver´Â °£´ÜÈ÷ ¾Æ·¡Ã³·³ °É¾ú´Ù. ¹°·Ð default´Ù. Èå
<!-- viewResolver --> <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean>
ÀÌ·¸°Ô Çϰí /articleÀ» È£ÃâÇϸé, ´ÙÀ½°ú °°Àº ¿¡·¯¸¦ ¸¸³ª°Ô µÈ´Ù.
°æ°í: No mapping found for HTTP request with URI [/WEB-INF/jsp/article.jsp] in DispatcherServlet with name 'dispatcher'
Èå... RequestMapping¸¦ Ÿ°í³ª¼, jsp¸¦ È£ÃâÇÏ·Á°í ÇÏ¿´´õ´Ï, /* url-pattern¿¡ °É·Áµé¾î ¿¡·¯°¡ ³ª´Â °ÍÀÌ´Ù.
À̸¦ ¾î¼¶õ ¸»Àΰ¡??? Èå
¿©±â¼ µîÀåÇÏ´Â °ÍÀÌ ¿ì¸®ÀÇ servlet specÀÌ´Ù.
SRV.11.2 Specification of Mappings ¸¦ º¸¸é ¾Æ·¡¿Í °°ÀÌ ³ª¿Í ÀÖ´Ù.
In theWeb application deployment descriptor, the following syntax is used to define mappings: 1. A string beginning with a ¡®/¡¯ character and ending with a ¡®/*¡¯ suffix is used for path mapping. 2. A string beginning with a ¡®*.¡¯ prefix is used as an extension mapping. 3.
A string containing only the ¡¯/¡¯ character indicates the "default"
servlet of the application. In this case the servlet path is the
request URI minus the context path and the path info is null. 4. All other strings are used for exact matches only.
1,
2, 4´Â ¾Ë°Ú´Âµ¥, 3¹øÀº Á» ±×·¸´Ù. ¤» ¿ì¸®ÀÇ ÁÖÀΰøÀº ¹Ù·Î ÀÌ 3¹øÀÌ´Ù. 3¹øÀ» º¸¸é '/'¸¸ µþ¶û ÀÖÀ» °æ¿ì¿¡´Â
default servlet¸¦ ź´Ù°í ÇÑ´Ù. ¾Æ ±×·±µ¥ ±×·¡¼ ¹¹? default servletÀÌ ¸Õµ¥? ¹» ¾î¼¶ó´Â °Å¾ß?
¤», ¾Æ! ÅèÄÏÀ» ÂüÁ¶Çϵµ·Ï ÇÏÀÚ. ÅèÄÏÀÇ conf/web.xml¸¦ ¿¾î¼ default servletÀ» ã¾Æº¸ÀÚ. ±×·¯¸é ÁÖ¼®¿¡ ÀÌ·± ¸»ÀÌ ³ª¿Â´Ù.
<!-- The default servlet for all web applications, that serves static --> <!-- resources. It processes all requests that are not mapped to other --> <!-- servlets with servlet mappings (defined either here or in your own --> <!-- web.xml file. This servlet supports the following initialization --> <!-- parameters (default values are in square brackets): -->
It processes all requests that are not mapped to other servlets with servlet mappings
ÀÌ
·± ¸»ÀÌ ÀÖ´Ù. ÀÌ default servletÀº servlet mapping¿¡ Çϳªµµ °É¸®Áö ¾Ê´Â ³à¼®µéÀ» ó¸®ÇÑ´Ù°í ÇÑ´Ù.
¿Â°® mappingÀ» Åë°úÇØ ¹ö¸° ³à¼®µéÀ» ¸»ÇÏ´Â °ÍÀÌ´Ù. ±×·¯¸é ¹¹°¡ ³²À»±î? ¹Ù·Î jpg, html µî Á¤ÀûÀÎ ¸®¼Ò½º¸¸ ³²°Ô
µÈ´Ù. ÅèÄϸ¸À¸·Îµµ À̹ÌÁö¸¦ º¸¿© ÁÙ ¼ö ÀÖ´Â °ÍÀº ÀÌ default servletÀÌ Àֱ⠶§¹®ÀÌ´Ù.
ÈåÇÏÇÏÇÏÇÏÇÏÇÏ~ ¿©±â¼ »ì¦ ÀܸӸ®¸¦ ±¼·Á º¸ÀÚ.. ¤»¤»
ÀÏ
¹ÝÀûÀ¸·Î web°ú was¸¦ ºÐ¸®Çؼ ¾²´Ï±î, jpg³ª html µî Á¤ÀûÀÎ ¸®¼Ò½º´Â web ¼¹ö°¡ ¸Ã¾Æ¼ ÇØ¾ßÇÑ´Ù. ±×¸®°í
³ª¸ÓÁöµéÀº was·Î ³Ñ¾î ¿Í¾ß ÇÑ´Ù. À§ÀÇ »óȲÀÇ ¹®Á¦´Â *.jsp°¡ DispatcherServlet¸¦ Ÿ¸é ¾ÈµÇ´Â »óȲÀÌ´Ù.
¤», jsp´Â was¿¡¼ 󸮸¦ ÇØ¾ß ÇÏ´Â °ÍÀÌÁö¸¸ /* url-pattern¿¡ ÀÇÇØ¼ DispatcherServlet¸¦ Ÿ¸é
¾ÈµÇ´Â »óȲÀÌ´Ù.
¤»¤» ¿ø·¡ default servletÀÇ ¸ñÀûÀ» »ì¦Äô ¹Ù²ã ¹ö¸®´Â °ÍÀÌ´Ù.
±×·±µ¥, SRV.11.2.1 Implicit Mappings¿¡ ³ª¿Í ÀÖ´Â °Íó·³, *.jsp´Â ÀÌ¹Ì mappingµÇ¾î ÀÖ´Ù. ÅèÄϾȿ¡ ¹ú½á µÇ¾î ¹ö·Á ÀÖ´Ù. ¹°·Ð ÀÌ conf/web.xml ÆÄÀÏ ¾È¿¡ ¸»ÀÌ´Ù. ¤»¤»
±×·¯¹Ç·Î *.jsp´Â ÅèÄÏ¿¡ °É·Á ÀÖ´Â servletÀ» Ÿ¸é µÇ°í, À̸¦ Åë°úÇÑ /articleÀº default servletÀ» Ÿ¸é µÈ´Ù´Â °ÍÀÌ´Ù. À̾ß... ÁäÀδÙ!!!!!
¾Ñ
±×·±µ¥, conf/web.xml¿¡ ÀÌ¹Ì default servletÀÌ ¼³Á¤µÇ¾î ÀÖ´Ù. ¾Ñ.. ¾î¼Áö? ¤»¤» SRV.11.2.1
Implicit Mappings(If a *.jsp mapping is defined by the Web application,
its mapping takes precedence over the implicit mapping.) ¿¡ ³ª¿Í ÀÖ´Â °Íó·³ ÇØ´ç
web application¿¡ ÀçÁ¤ÀǸ¦ ÇÏ°Ô µÇ¸é, implicit Mapping º¸´Ù ¿ì¼±ÀûÀ¸·Î Àû¿ëµÈ´Ù°í ÇÑ´Ù. ÈåÈå.
ÀÌ·¸°Ô ÇØ¼ *.jsp¸¦ Á¦¿ÜÇϰí SpringÀÇ DispatcherServletÀ» ÅÂ¿ï ¼ö ÀÖ´Â °ÍÀÌ´Ù. ¾Æ·¡Ã³·³ url-pattern¸¸ /* ¿¡¼ /·Î ¹Ù²ã ¹ö¸®¸é µÈ´Ù. ¾Æ·¡Ã³·³.. Èå
<servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
|