MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology

Spring Programing laungage

Spring Projects

Spring Project 1

Example of Validate Interface
Previous Home Next

Directory Structure of Spring MVC application is given below:

step 1:

Create index.jsp file

<%@page contentType="text/html" pageEncoding="UTF-8"%>

step 2:

Create web.xml file

<web-app id="WebApp_ID" version="2.4"
<display-name>Spring MVC Application</display-name>


step 3:

Create dispatcher-servlet.xml file

<beans xmlns=""
<bean id="messageSource"
<property name="basename" value="message" />
<bean name="/userInfo.bean" class="com.r4r.UserInfoController">
<property name="commandClass" value="com.r4r.UserInfo"/>
<property name="commandName" value="user"/>
<property name="formView" value="formPage"/>
<property name="successView" value="successPage"/>
<property name="validator">
<bean class="com.r4r.MyValidator"/>
<bean id="viewResolver"
	InternalResourceViewResolver" >
<property name="prefix">
<property name="suffix">

step 4:

Create file

package com.r4r;
import javax.servlet.http.*;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
public class UserInfoController extends SimpleFormController {
public UserInfoController() {
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response,
Object command, BindException errors)
throws Exception {
UserInfo userinfo=(UserInfo)command;
model.addObject("name", userinfo.getName());
model.addObject("dob", userinfo.getDob());
model.addObject("address", userinfo.getAddress());
model.addObject("city", userinfo.getCity());
return model;

step 5:

Create file

package com.r4r;
public class UserInfo {
String name;
String dob;
String address;
String city;
public String getName() {
return name;
public void setName(String name) { = name;
public String getDob() {
return dob;
public void setDob(String dob) {
this.dob = dob;
public String getAddress() {
return address;
public void setAddress(String address) {
this.address = address;
public String getCity() {
return city;
public void setCity(String city) { = city;

step 6:

Create file

package com.r4r;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
public class MyValidator implements Validator {
public boolean supports(Class arg0) {
return UserInfo.class.isAssignableFrom(arg0);
public void validate(Object arg0, Errors errors) {
(errors, "name","");
(errors, "dob","user.dob");
(errors, "address","user.address");
(errors, "city","");

step 7:

Create file = UserName is required!
user.dob = Date of birth is required!
user.address = Address is required! = City is required!

step 8:

Create formPage.jsp file

<%@taglib uri="" prefix="form"%>
<title>Validation Information Example</title>
.error {
color: #ff0000;
font-style: italic;
color: #ff0000;
background-color: black;
text-align: center;
<form:form commandName="user" method="POST">
<form:errors path="*" cssClass="errorblock" element="div"/>
<td><form:input path="name"/></td>
<td><form:errors path="name" cssClass="error"/></td>
<td>Date Of Birth:-</td>
<td><form:input path="dob"/></td>
<td><form:errors path="dob" cssClass="error"/></td>
<td><form:input path="address"/></td>
<td><form:errors path="address" cssClass="error"/></td>
<td><form:input path="city"/></td>
<td><form:errors path="city" cssClass="error"/></td>
<tr><td><input type="submit" value="Submit"/></td></tr>

step 9:

Create successPage.jsp file

<%@taglib uri="" prefix="c"%>
<h4>User Information</h4>
<h5>UserName:-<c:out value="${name}"/></h5>
<h5>Date of Birth:-<c:out value="${name}"/></h5>
<h5>Address:-<c:out value="${name}"/></h5>
<h5>City:-<c:out value="${name}"/></h5>


Previous Home Next