1. 이클립스 File >> New >> Project >> Spring Project
>> Spring MVC Project
프로젝트이름을 SpringHello라고 하자.
2. topLevelPackage는 com.onjprogramming.helloworld라고 하자.
마지막 helloworld가 web app의 이름이 된다.
프로젝트이름을 SpringHello라고 하자.
2. topLevelPackage는 com.onjprogramming.helloworld라고 하자.
마지막 helloworld가 web app의 이름이 된다.
즉 나중에 실행시 브라우저에서 http://localhost:8080/helloworld 라고 하는 것이다.
입력 후 Next를 클릭
3. 이제 이클립스에 SprignHello 라는 프로젝트가 생긴 것을 확인 할 수 있을 것이다.
3. 이제 이클립스에 SprignHello 라는 프로젝트가 생긴 것을 확인 할 수 있을 것이다.
4. HelloWorldController.java
package com.onjprogramming.helloworld.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloWorldController {
@RequestMapping("/hello")
public ModelAndView helloWorld() {
String message = "Hello, Spring 3.X!";
return new ModelAndView("hello", "message", message);
}
}
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HelloWorldController {
@RequestMapping("/hello")
public ModelAndView helloWorld() {
String message = "Hello, Spring 3.X!";
return new ModelAndView("hello", "message", message);
}
}
5. /WEB-INF/jsp/hello.jsp
<html>
<head>
<title>Spring 3.X MVC Hello World</title>
</head>
<body>
${message}
</body>
</html>
<head>
<title>Spring 3.X MVC Hello World</title>
</head>
<body>
${message}
</body>
</html>
6. /WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>springhello</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-name>springhello</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springhello</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
<servlet-name>springhello</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
7. /WEB-INF/springhello-servlet.xml
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd“>
<context:component-scan base-package=“com.onjprogramming.helloworld.controller" />
<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>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd“>
<context:component-scan base-package=“com.onjprogramming.helloworld.controller" />
<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>
</beans>
[개강임박강좌, 오프라인교육장에 오시면 보다 자세히 배울 수 있습니다.]
오라클자바커뮤니티에서 운영하는 개발자 전문교육 ,개인80%환급(www.onjprogramming.co.kr)
[주간]
[11/18]Spring3.X, MyBatis, Hibernate실무과정
[11/18]iPhone 하이브리드 앱 개발 실무과정
[11/20]SQL초보에서실전전문가까지
[11/20]안드로이드개발자과정
[평일야간]
[11/13]C#,ASP.NET마스터
[11/19]iPhone하이브리드앱개발실무과정
[11/19]안드로이드개발자과정
[11/20]초보자를위한실전SQL
[11/21]JAVA&WEB프레임워자실무과정
[11/21]Spring3.X, MyBatis, Hibernate실무과정
[주말]
[11/16]JAVA&WEB프레임워크실무과정
[11/16]웹퍼블리싱 마스터
[11/16]Spring3.X,MyBatis,Hibernate실무과정
[11/16]SQL초보에서전문가까지
[11/16]PL/SQL,오라클힌트,SQL튜닝,사례연구
[11/23]C#,ASP.NET마스터
오라클자바커뮤니티에서 운영하는 개발자 전문교육 ,개인80%환급(www.onjprogramming.co.kr)
[주간]
[11/18]Spring3.X, MyBatis, Hibernate실무과정
[11/18]iPhone 하이브리드 앱 개발 실무과정
[11/20]SQL초보에서실전전문가까지
[11/20]안드로이드개발자과정
[평일야간]
[11/13]C#,ASP.NET마스터
[11/19]iPhone하이브리드앱개발실무과정
[11/19]안드로이드개발자과정
[11/20]초보자를위한실전SQL
[11/21]JAVA&WEB프레임워자실무과정
[11/21]Spring3.X, MyBatis, Hibernate실무과정
[주말]
[11/16]JAVA&WEB프레임워크실무과정
[11/16]웹퍼블리싱 마스터
[11/16]Spring3.X,MyBatis,Hibernate실무과정
[11/16]SQL초보에서전문가까지
[11/16]PL/SQL,오라클힌트,SQL튜닝,사례연구
[11/23]C#,ASP.NET마스터
댓글 없음:
댓글 쓰기