src/main에 있던 webapp을 건드렸다 만들었다 하다가



 


webapp 디렉토리 폴더의 모양이

처음엔 위에 사진처럼 디렉토리 안에 지구(?)모양이 있었는데 




잠깐 이름바꾸면서인가?지웠다가 다시만들었는데 저 지구모양이 사라지면서

web.xml에 servlet-mapping이 에러가났다. 아래처럼




에러 내용은 저렇지만 maven에는 어느정도 다 넣었다고 생각한다.



그래서 디렉토리를 지구가 들어있는 디렉토리로 바꾸려고 해 보았지만 못찾아서...다른 메이븐+spring webapp 프로젝트를 만들어 거기있는 webapp을 복사 해 왔다.


복사 해 온 지구들어있는 디렉토리에 web.xml에서는 에러가 나지않았다.




Posted by 010562
1.pom.xml

<project xmlns="...">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.sample</groupId>
<artifactId>webservice-test</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>webservice-test Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.2.4.RELEASE</version>
</dependency>

</dependencies>
<build>
<finalName>webservice-test</finalName>
</build>
</project>

2. web.xml

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app xmlns:xsi="...">
<display-name>Archetype Created Web Application</display-name>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>

3. dispatcher-servelt.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans ... >

<context:component-scan base-package="net.daum.game" ></context:component-scan>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"/>
<property name="suffix" value=".jsp"/>
</bean>

<bean class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="suffix" value=".vm" />
<property name="order" value="1" />
</bean>

<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/velocity/" />

</bean>
</beans>

4. velocity/myprofile.vm

<html>
<body>
Name -> $mName
<br>
Age -> $mAge
<br>
gender -> $mGender
<br>
<hr>
<br>
My name is $mName. I'm $mAge years old.

#set( $mAge = 25)

</body>
</html>

5. ProfileController

package com.company.sample;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
* Created by sm on 2016. 1. 22..
*/
@Controller
public class ProfileController {

@RequestMapping(value = "profile")
public ModelAndView ProfileView() {

ModelAndView mv =
new ModelAndView();
mv.setViewName("myprofile");
mv.addObject("mName", "sm");
mv.addObject("mAge", "24");
mv.addObject("mGender", "female");

return mv;
}
}


프로젝트 구성

(모자이크부분은 com.company.sample)


Posted by 010562