본문 바로가기

spring/Web

<url-pattern>/</url-pattern>

모든 요청에 대하여 처리를 할경우


==========================================================================================================================================

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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>s_mvc5_arrange_anno</display-name>

  

  <servlet>

  <servlet-name>hello</servlet-name> 

  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

  </servlet>

  <servlet-mapping>

  <servlet-name>hello</servlet-name>

<!--  

<url-pattern>*.do</url-pattern>  부분 요청 처리(확장자를 씀)

-->

<url-pattern>/</url-pattern> <!-- 모든 요청을 다 받음(확장자를 쓸수도 안쓸수도 있음) -->

  </servlet-mapping>

  

</web-app>


==========================================================================================================================================

servlet 설정파일


<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

<!--  web.xml 에서 url-pattern이 다음과 같을 경우 : <url-pattern>/</url-pattern> -->

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">

<property name="alwaysUseFullPath" value="true"/>

</bean>

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">

<property name="alwaysUseFullPath" value="true"/>

</bean>

<mvc:default-servlet-handler/>

<context:annotation-config/> <!-- 생략가능 -->

<context:component-scan base-package="pack"/>

<!-- ViewResolver : InternalResourceViewResolver -->

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/"/>

<property name="suffix" value=".jsp"/>

</bean>


</beans>



Controller 에서는 다음과 같이 처리해 줄수 있다.


@RequestMapping({"hello","ni*","hello.html"})