티스토리 뷰
maven을 이용한 springframework 개발환경 설정.
pom 파일만 있으면 끝.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rocksea</groupId>
<artifactId>rocksea</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>rocksea Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>rocksea</finalName>
</build>
</project>
WEB-INF/web.xml
<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>Archetype Created Web Application</display-name>
<!-- default page -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- ContextLoaderListener는 기본값으로 /WEB-INF/applicationContext.xml 파일을 참조한다.
추가 설정을 통해 applicationContext.xml 말고 다른 파일을 참조 하게 할 수도 있다.
<listener>
<display-name>SpringContextLoader</display-name>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
-->
<!-- servelt이 호출되면 실행될 spring의 DispatcherServlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- .do는 dispatcher servlet 이 처리 -->
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 한글처리 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
WEB-INF/dispatcher-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- annotation setting -->
<context:annotation-config />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" p:order="1" />
<bean id="testController" class="com.rocksea.controller.TestController" />
</beans>
com/rocksea/controller
package com.rocksea.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class TestController {
@RequestMapping("/test1.do")
public ModelAndView helloworld(HttpServletRequest request, HttpServletResponse response) throws Exception {
String[] strArr = new String[10];
String message = "Hello World!!";
strArr[0] = "test1";
strArr[1] = "test2";
strArr[2] = "test3";
strArr[3] = "test4";
strArr[4] = "test5";
ModelAndView mnv = new ModelAndView();
mnv.setViewName("resultPage");
mnv.addObject("message", message);
mnv.addObject("rocksea", message);
mnv.addObject("strArray", strArr);
return mnv;
}
}
WEB-INF/jsp/resultPage.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h2>${message}</h2>
<h2>${rocksea}</h2>
<h2>${strArray[4]}</h2>
</body>
</html>
'Developer' 카테고리의 다른 글
[ expect ] telnet, ssh 자동화 script (0) | 2012.10.09 |
---|---|
[ console ] commands (0) | 2012.10.08 |
[ Perl ] FTP Upload (0) | 2012.09.28 |
Heuristic (0) | 2012.09.25 |
[ redis ] master , slave 설정 (0) | 2012.09.14 |
- Total
- Today
- Yesterday
- 영작
- it
- 해외여행
- maven
- 다낭
- hdfs
- NGINX
- 베트남
- 여행
- 가정법
- memcached
- Python Django
- 도덕경
- 스페인 여행
- 비지니스 영어
- 조동사
- Business English
- Python
- 대명사 구문
- PostgreSQL
- nodejs
- 비교구문
- ubuntu
- k8s
- JBOSS
- mongoDB
- redis
- 영문법
- hadoop
- AWS
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |