There are following step to create a simple Spring MVC Program.
@controller annotation class is process the user request and send the appropriate view page.
@request mapping is use for match the URL so that my method execute.
web.xml file is use for configure spring-config.xml file.
From InternalResourceViewResolver method we are showing response in jsp file.
Below are jar file use:-
Spring core jar file
Spring web jar file
Index.jsp class:-
Welcome to Spring MVC Login page
Employee.java class:-
public class Employee {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Web.xml :-
mvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
/WEB-INF/spring-config.xml
1
mvc
/
spring-config.xml :-
Controller class:-
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class EmployeeController {
@RequestMapping(value = "/hello", method = RequestMethod.POST)
public String test(Employee emp, Model model) {
System.out.println("employee page");
model.addAttribute("name", emp.getName());
return "Employee";
}
}
Employee.jsp output:- :-
<%@ page language="java” contentType=“text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
Welcome to ${name}
output:-