Create Spring MVC Project
On the Eclipse, create a Spring MVC project
Enter Project Information:
Name: Lesson1SpringMVC
Group: [Link]
Artifact: Lesson1SpringMVC
Description: Lesson 1 Spring MVC
Package: [Link].lesson1
Select the technologies and libraries to be used:
Web
Click Next button to show Site Information for project
Click Finish button to finish create Spring MVC project
Configure [Link]
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="[Link]
xmlns:xsi="[Link]
xsi:schemaLocation="[Link]
[Link]
<modelVersion>4.0.0</modelVersion>
<groupId>[Link]</groupId>
<artifactId>LearnSpringMVCWithRealApps</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>LearnSpringMVCWithRealApps</name>
<description>Learn Spring MVC with Real Apps</description>
<parent>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>[Link]</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<[Link]>UTF-8</[Link]>
<[Link]>UTF-8</[Link]>
<[Link]>1.8</[Link]>
</properties>
<dependencies>
<!-- Spring MVC -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- JSTL tag lib -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>[Link]-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- Tomcat for JSP rendering -->
<dependency>
<groupId>[Link]</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>[Link]</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>[Link]</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Configure [Link]
1. [Link] = /WEB-INF/views/
2. [Link] = .jsp
3. [Link]-path-pattern=/resources/**
4. [Link]=9596
Create Controller
Create new package named [Link]. In this package, create new controller name
HomeController as below:
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@Controller
@RequestMapping(value = "home")
public class HomeController {
@RequestMapping(method = [Link])
public String index() {
return "home/index";
}
Create View
Create new folders with path webapp\WEB-INF\views in src\main. In views folder, create new
folder named demo. In demo folder, create new views as below:
Index View
Create new jsp file named [Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Index View</title>
</head>
<body>
<h3>Welcome to Spring MVC</h3>
</body>
</html>
Structure of Spring MVC Project
Run Application
Select [Link] file in [Link] package, right click and
select Run As/Spring Boot App menu
Access index method in demo controller with following url: [Link]
Output
Access hi method in demo controller with following url: [Link]
fullName=Kevin
Output
Access sum method in demo controller with following url: [Link]
a=2&b=3
Output