diff --git a/SpringMVCFormExample/WebContent/META-INF/MANIFEST.MF b/SpringMVCFormExample/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..254272e1c0 --- /dev/null +++ b/SpringMVCFormExample/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/SpringMVCFormExample/WebContent/WEB-INF/dispatcher-servlet.xml b/SpringMVCFormExample/WebContent/WEB-INF/dispatcher-servlet.xml new file mode 100644 index 0000000000..1fc94effba --- /dev/null +++ b/SpringMVCFormExample/WebContent/WEB-INF/dispatcher-servlet.xml @@ -0,0 +1,27 @@ + + + + + + + + + + /WEB-INF/views/ + + + .jsp + + + + \ No newline at end of file diff --git a/SpringMVCFormExample/WebContent/WEB-INF/views/employeeAdded.jsp b/SpringMVCFormExample/WebContent/WEB-INF/views/employeeAdded.jsp new file mode 100644 index 0000000000..1457bc5fc8 --- /dev/null +++ b/SpringMVCFormExample/WebContent/WEB-INF/views/employeeAdded.jsp @@ -0,0 +1,24 @@ +<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> + + +Spring MVC Form Handling + + + +

Submitted Employee Information

+ + + + + + + + + + + + + +
Name :${name}
ID :${id}
Contact Number :${contactNumber}
+ + \ No newline at end of file diff --git a/SpringMVCFormExample/WebContent/WEB-INF/views/employeeHome.jsp b/SpringMVCFormExample/WebContent/WEB-INF/views/employeeHome.jsp new file mode 100644 index 0000000000..f86fc19146 --- /dev/null +++ b/SpringMVCFormExample/WebContent/WEB-INF/views/employeeHome.jsp @@ -0,0 +1,38 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> + + + + + +SpringMVCExample + + + +

Welcome, Enter The Employee Details

+ + + + + + + + + + + + + + + + + + +
Name
Id
Contact Number
+
+ + + + \ No newline at end of file diff --git a/SpringMVCFormExample/WebContent/WEB-INF/views/error.jsp b/SpringMVCFormExample/WebContent/WEB-INF/views/error.jsp new file mode 100644 index 0000000000..8f3d83af17 --- /dev/null +++ b/SpringMVCFormExample/WebContent/WEB-INF/views/error.jsp @@ -0,0 +1,20 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +SpringMVCExample + + + +

Pleas enter the correct details

+ + + + +
Retry
+ + + + \ No newline at end of file diff --git a/SpringMVCFormExample/WebContent/WEB-INF/web.xml b/SpringMVCFormExample/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000000..47dd114f2a --- /dev/null +++ b/SpringMVCFormExample/WebContent/WEB-INF/web.xml @@ -0,0 +1,16 @@ + + + SpringMVCFormExample + + dispatcher + org.springframework.web.servlet.DispatcherServlet + 1 + + + dispatcher + / + + + index.jsp + + \ No newline at end of file diff --git a/SpringMVCFormExample/WebContent/index.jsp b/SpringMVCFormExample/WebContent/index.jsp new file mode 100644 index 0000000000..1ecfcec9d7 --- /dev/null +++ b/SpringMVCFormExample/WebContent/index.jsp @@ -0,0 +1,18 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" + pageEncoding="ISO-8859-1"%> + + + + +Spring MVC Examples + + + +

Spring MVC Examples

+ + + + \ No newline at end of file diff --git a/SpringMVCFormExample/src/com/demo/controllers/EmployeeController.java b/SpringMVCFormExample/src/com/demo/controllers/EmployeeController.java new file mode 100644 index 0000000000..d4bc8e44ad --- /dev/null +++ b/SpringMVCFormExample/src/com/demo/controllers/EmployeeController.java @@ -0,0 +1,34 @@ +package com.demo.controllers; + +import javax.validation.Valid; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.ModelMap; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.servlet.ModelAndView; + +import com.demo.form.Employee; + +@Controller +public class EmployeeController { + + @RequestMapping(value = "/employee", method = RequestMethod.GET) + public ModelAndView showForm() { + return new ModelAndView("employeeHome", "employee", new Employee()); + } + + @RequestMapping(value = "/addEmployee", method = RequestMethod.POST) + public String submit(@Valid @ModelAttribute("employee")Employee employee, BindingResult result, + ModelMap model) { + if (result.hasErrors()) { + return "error"; + } + model.addAttribute("name", employee.getName()); + model.addAttribute("contactNumber", employee.getContactNumber()); + model.addAttribute("id", employee.getId()); + return "employeeAdded"; + } +} diff --git a/SpringMVCFormExample/src/com/demo/form/Employee.java b/SpringMVCFormExample/src/com/demo/form/Employee.java new file mode 100644 index 0000000000..cf7fb574cf --- /dev/null +++ b/SpringMVCFormExample/src/com/demo/form/Employee.java @@ -0,0 +1,33 @@ +package com.demo.form; + +public class Employee { + + private String name; + private long id; + private String contactNumber; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getContactNumber() { + return contactNumber; + } + + public void setContactNumber(String contactNumber) { + this.contactNumber = contactNumber; + } + +}