오라클자바커뮤니티에서 설립한 개발자실무교육6년차 오엔제이프로그래밍 실무교육센터
(신입사원채용무료교육, 오라클, SQL, 튜닝, 자바, 스프링,
Ajax, jQuery, 안드로이드, 아이폰, 닷넷, C#, ASP.Net)
스프링3.X게시판&오라클힌트,SQL튜닝,사례연구과정개설
스프링3.X게시판&오라클힌트,SQL튜닝,사례연구과정개설
1. 이클립스 상단 왼쪽 File >> New >> Project >> Spring Project
>> Spring MVC Project
상단에 프로젝트이름을 SpringHello라고 하자.
2. topLevelPackage는 com.onjprogramming.helloworld라고 하자.
helloworld가 app의 이름이 된다. 즉 나중에 실행시 브라우저에서 http://localhost:8080/helloworld 라고 하는 것이다. 입력 후 Next를 클릭
3. 이제 이클립스에 SprignHello 라는 프로젝트가 생긴 것을 확인 할 수 있을 것이다.
4. 소스 코드
[HelloWorldController.java]
상단에 프로젝트이름을 SpringHello라고 하자.
2. topLevelPackage는 com.onjprogramming.helloworld라고 하자.
helloworld가 app의 이름이 된다. 즉 나중에 실행시 브라우저에서 http://localhost:8080/helloworld 라고 하는 것이다. 입력 후 Next를 클릭
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);
}
}
[/WEB-INF/jsp/hello.jsp]
<html>
<head>
<title>Spring 3.X MVC Hello World</title>
</head>
<body>
${message}
</body>
</html>
[/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">
<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>
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);
}
}
[/WEB-INF/jsp/hello.jsp]
<html>
<head>
<title>Spring 3.X MVC Hello World</title>
</head>
<body>
${message}
</body>
</html>
[/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">
<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>
[/WEB-INF/springhello-servletr.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>
<?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>
댓글 없음:
댓글 쓰기