Spring 프로젝트 설정
(Application project)
-path : src (Web project)
-path : WebContent> WEB-INF
- 웹 프로젝트시 예시
스프링 Hello World
1. DispatchServlet 설정 및 스프링 컨텍스트 설정 web.xml
웹 프로젝트 설정 파일인 web.xml파일에 요청을 전달 받을 DispatcherServlet과
공통으로 사용할 어플리케이션 컨텍스트 설정
<?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>SpringTest</display-name> <!-- 서블릿이름은 매핑이름과 동일해야하며 –servlet.xml 서블릿 설정 파일 이름과 동일해야함. --> <servlet> <servlet-name>springTest</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <!-- 모든 요청을 *.do로 처리. 즉! 하나의 서블릿으로 모든 요청 처리! --> <servlet-mapping> <servlet-name>springTest</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <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> |
2. HandlerMapping 설정 파일에 설정 추가 (WebContent> WEB-INF) springTest-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans" <!-- the application context definition for the springapp DispatcherServlet --> |
3. 컨트롤러 구현 및 설정
import java.util.Calendar; import javax.servlet.http.HttpServletRequest; import org.springframework.web.servlet.ModelAndView; public class HelloController extends AbstractController { //컨트롤러는 처리 결과를 ModelAndView에 담아 DispatcherServlet에 전달함. (data,view) } |
4. 뷰 생성
<?xml version="1.0" encoding="EUC-KR" ?> <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" /> <title>Insert title here</title> </head> <body> 인사말 : <strong>${greeting}</strong> </body> </html><SPAN id=tx_marker_caret></SPAN> |
'개발 Programming > SPRING' 카테고리의 다른 글
AOP (0) | 2010.05.03 |
---|---|
스프링 데이터소스 연결 (0) | 2009.11.10 |
스프링 프레임워크 소개( Spring Framwork Introduce) (0) | 2009.11.05 |
spring_dwr (0) | 2009.11.05 |
spring_tile_ (0) | 2009.11.05 |