Create Spring web app.
source: http://www.programcreek.com/2014/02/spring-mvc-helloworld-using-maven-in-eclipse/
This commit is contained in:
parent
0e1c54c60a
commit
b1dd0dd0bb
45
pom.xml
Normal file
45
pom.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<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.camillepradel.movierecommender</groupId>
|
||||
<artifactId>MovieRecommender</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>MovieRecommender Maven Webapp</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<spring.version>4.3.1.RELEASE</spring.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Spring dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>MovieRecommender</finalName>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,23 @@
|
||||
package com.camillepradel.movierecommender.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
@Controller
|
||||
public class MainController {
|
||||
String message = "Welcome to Spring MVC!";
|
||||
|
||||
@RequestMapping("/hello")
|
||||
public ModelAndView showMessage(
|
||||
@RequestParam(value = "name", required = false, defaultValue = "World") String name) {
|
||||
System.out.println("in controller");
|
||||
|
||||
ModelAndView mv = new ModelAndView("helloworld");
|
||||
mv.addObject("message", message);
|
||||
mv.addObject("name", name);
|
||||
return mv;
|
||||
}
|
||||
}
|
21
src/main/webapp/WEB-INF/dispatcher-servlet.xml
Normal file
21
src/main/webapp/WEB-INF/dispatcher-servlet.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
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">
|
||||
|
||||
<context:component-scan base-package="com.camillepradel.movierecommender.controller" />
|
||||
|
||||
<bean
|
||||
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
|
||||
<property name="prefix">
|
||||
<value>/WEB-INF/views/</value>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<value>.jsp</value>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
16
src/main/webapp/WEB-INF/views/helloworld.jsp
Normal file
16
src/main/webapp/WEB-INF/views/helloworld.jsp
Normal file
@ -0,0 +1,16 @@
|
||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
|
||||
<!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=ISO-8859-1">
|
||||
<title>Spring 4 MVC -HelloWorld</title>
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
<h2>Hello World</h2>
|
||||
<h2>
|
||||
${message} ${name}
|
||||
</h2>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
29
src/main/webapp/WEB-INF/web.xml
Normal file
29
src/main/webapp/WEB-INF/web.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
|
||||
|
||||
<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>
|
||||
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
|
||||
</context-param>
|
||||
|
||||
<listener>
|
||||
<listener-class>
|
||||
org.springframework.web.context.ContextLoaderListener
|
||||
</listener-class>
|
||||
</listener>
|
||||
</web-app>
|
19
src/main/webapp/index.jsp
Normal file
19
src/main/webapp/index.jsp
Normal file
@ -0,0 +1,19 @@
|
||||
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
|
||||
|
||||
pageEncoding="ISO-8859-1"%>
|
||||
<!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=ISO-8859-1">
|
||||
<title>Spring 4 MVC - HelloWorld Index Page</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center>
|
||||
<h2>Hello World</h2>
|
||||
<h3>
|
||||
<a href="hello?name=Eric">Click Here</a>
|
||||
</h3>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user