commit
279b527cf4
@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5">
|
|
||||||
<javaee:display-name>SpringMVCFormExample</javaee: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>
|
|
||||||
<welcome-file-list>
|
|
||||||
<welcome-file>index.jsp</welcome-file>
|
|
||||||
</welcome-file-list>
|
|
||||||
</web-app>
|
|
@ -1,34 +0,0 @@
|
|||||||
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";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -12,7 +12,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<h3>Welcome, Enter The Employee Details</h3>
|
<h3>Welcome, Enter The Employee Details</h3>
|
||||||
|
|
||||||
<form:form method="POST" action="/SpringMVCFormExample/addEmployee"
|
<form:form method="POST" action="/spring-mvc-forms/addEmployee"
|
||||||
commandName="employee">
|
commandName="employee">
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
19
spring-mvc-forms/WebContent/WEB-INF/web.xml
Normal file
19
spring-mvc-forms/WebContent/WEB-INF/web.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5">
|
||||||
|
<javaee:display-name>SpringMVCFormExample</javaee: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>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>index.jsp</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
</web-app>
|
@ -0,0 +1,33 @@
|
|||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
33
spring-mvc-forms/src/com/demo/form/Employee.java
Normal file
33
spring-mvc-forms/src/com/demo/form/Employee.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user