sitelink1 | |
---|---|
sitelink2 | |
sitelink3 | |
extra_vars6 |
http://blog.empas.com/ahnyounghoe/13186543
<display-name>
wa.articlelink</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
일단 Spring MVC 기반으로 요청이 처리 되도록 합니다. 좀 더 그럴싸한 말로는 Spring MVC 기반의 HTTP 요청 메커니즘 구동을 해보는거죠. (써놓고 나니 재수없네요..ㅋㅋ)
3. Web Application Context(Front Controller) 설정
Front Controller 라는 말은 J2EE 패턴에서 유래된 것입니다. JSP 모델 1 방식이 개별적인 기능을 하는 서블릿들에게 요청을 분산시켰다면, JSP 모델 2는 일단 앞단의 서블릿(이 녀석이 Front Controller)이 요청을 받아서 적절한 처리기로 분산되게 한 것이죠.
'왜 이렇게 하느냐?'에 대한 대답을 가장 적은 노력으로 얻을 수 있는 방법은 기업에서 대표 전화를 두는 이유를 생각해보는 것입니다.
아무튼 Spring에선 Front Controller 역할을 하는 것이 DispatcherServlet 입니다. web.xml에 DispatcherServlet을 설정하는 것은 비단 서블릿을 쓰겠다고 정의하는 것만은 아닙니다. DispatcherSetvelt을 관문으로 하나의 요청 처리 집단(컨텍스트)이 정의됩니다. 이것을 Web Application Context라고 하고, 대개는 xml 파일로 이 집단에 속한 객체(bean)들을 정의합니다.
먼저 web.xml에 서블릿 부터 정의하죠. 이클립스가 자동 생성해준 web.xml(web 폴더 밑의 WEB-INF에 있죠)를 보면 다음과 같습니다.
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
wa.articlelink</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>
</web-app>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
wa.articlelink</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>
</web-app>
관문 페이지(welcome-file)로 잔뜩 등록되어 있는 것을 index.html만 남기겠습니다.
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
wa.articlelink</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
wa.articlelink</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
그리고 서블릿 등록을 추가합니다.
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<!-- Spring Front Controller 등록 -->
<servlet>
<servlet-name>article</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>article</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>article</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-name>article</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<display-name>
wa.articlelink</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
servlet 태그를 보면 article이라는 이름으로 DispatcherServlet을 부르겠다고 정의한 것입니다. article이라는 이름은 해당 Web Application Context를 대표하는 이름이 됩니다. 그래서, web/WEB-INF에 article-servlet.xml 이라는 이름으로 해당 컨텍스트에 소속된 객체를 정의합니다.
servlet-mapping 정의를 보면 .do로 끝나는 요청은 모두 article 서블릿으로 보내란 것이죠.
org.springframework.web.servlet.DispatcherServlet를 사용할 것이니까 이 클래스가 포함된 라이브러리 파일을 클래스패스에 등록해야죠. spring.jar를 받아서 web/WEB-INF/lib에 넣습니다.