database spring registration form

We are going to discuss about spring registration form. We have created simple spring registration form with many fields. Here we can store all data in database.

database spring registration form

We are going to discuss about  database spring registration form. We have created simple spring registration form with many fields. Here we can store all data in database. We then create jsp registration form. We have used controller and we are using database connectivity and we have created interface and implementation of class.

Following is the example of simple spring registration form:-

We have created this database which you can copy and use it.

CREATE TABLE `registrationform` (                        
                    `rollNno` int(11) NOT NULL AUTO_INCREMENT,             
                    `name` varchar(30) DEFAULT NULL,                       
                    `userid` varchar(50) DEFAULT NULL,                     
                    `password` varchar(20) DEFAULT NULL,                   
                    `email` varchar(20) DEFAULT NULL,                      
                    `address` varchar(20) DEFAULT NULL,                    
                    `city` varchar(30) DEFAULT NULL,                       
                    `state` varchar(30) DEFAULT NULL,                      
                    `phoneno` varchar(20) DEFAULT NULL,                    
                    PRIMARY KEY (`rollNno`)                                
                  ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1  


  1.  We have created model bean class "Form. java" and we are creating many variables field  name, Userid, password, email, address, city, state, phoneNo and we are making setter and getter method all variable fields like as:-
  • Form .java
package model;

public class Form {
	private Integer rollno;
	private String name;
	private String Userid;
	private String password;
	private String email;
	private String address;
	private String city;
	private String State;
	private String phoneNo;

	public Integer getRollno() {
		return rollno;

	public void setRollno(Integer rollno) {
		this.rollno = rollno;

	public String getName() {
		return name;

	public void setName(String name) { = name;

	public String getUserid() {
		return Userid;

	public void setUserid(String userid) {
		Userid = userid;

	public String getPassword() {
		return password;

	public void setPassword(String password) {
		this.password = password;

	public String getEmail() {
		return email;

	public void setEmail(String email) { = email;

	public String getAddress() {
		return address;

	public void setAddress(String address) {
		this.address = address;

	public String getCity() {
		return city;

	public void setCity(String city) { = city;

	public String getState() {
		return State;

	public void setState(String state) {
		State = state;

	public String getPhoneNo() {
		return phoneNo;

	public void setPhoneNo(String phoneNo) {
		this.phoneNo = phoneNo;

2  Now we create model bean class "". In this class we are creating two variables name id and name. We have all variables name generate setter and getter method. We use this for class initiation values and set and get values.

package model;

public class City {
	private int id;
	private String name;

	public City() {

	public City(int id, String name) {
		super(); = id; = name;

	public Integer getId() {
		return id;

	public void setId(Integer id) { = id;

	public String getName() {
		return name;

	public void setName(String name) { = name;

Now Next Step

3 We have created controller class "" to handle all form and @RequestMapping we used for implementation of all controller interface.

package controller;

import java.util.List;

import model.City;
import model.Form;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import Service.AppServiceImp;
import Service.Demo;

public class MainController {
private Demo service;

public void setService(AppServiceImp appServiceImp) {
this.service = appServiceImp;

public List<City> loadAllCity() {
return service.loadAllCity();

public java.util.List<String> loadAllState() {
return service.loadAllState();

public String loadForm(Model model, Form field) {
model.addAttribute("field", field);
return "rgistration";

public String processForm(Model model, Form field) {
model.addAttribute("field", field);
return "Success";

4 Now We are StudentMapping class we implements RowMapper and we have used resultSet method it mens set of all value  in variable field.

package domain;

import java.sql.SQLException;

import model.Form;

import org.springframework.jdbc.core.RowMapper;

import com.mysql.jdbc.ResultSet;

public abstract class StudentMapping implements RowMapper<Form> {

public Form mapRow(ResultSet resultSet, int rowNum) throws SQLException {
Form student = new Form();
return student;
  • rgistration.jsp

5 We are create user registration jsp form we are many field create Name,UserId, Password, Emailid, Address ,City ,State, and phoneNo and we cac user store all values in database click by submit button.

<%@taglib prefix="form" uri=""%>
<title>Registration Form</title>
<h2 align="center">Student Registration Form</h2>
<hr />
<table align="center" cellpadding="5" cellspacing="5">
<form:form commandName="field" method="POST" action="process-form">

<td><form:input path="name" />

<td><form:input path="Userid" />

<td><form:password path="password" />

<td>Email Id</td>
<td><form:input path="email" />

<td><form:textarea path="address" />
<td><form:select path="city">
<form:option value="" label="Please Select" />
<form:options items="${city}" itemValue="name" itemLabel="name" />
</form:select><br />
<font color="red"><form:errors path="city" /></font></td>

<td><form:select path="state" items="${state}" /><br />
<font color="red"><form:errors path="state" /></font></td>
<td><form:input path="phoneNo" />
<td><input type="submit" name="save" /></td>
  • dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
xmlns:xsi="" xmlns:p=""

<context:component-scan base-package="*" />

<bean id="viewResolver"
<property name="prefix">
<property name="suffix">

<bean id="myAppDataSource"
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/naulej" />
<property name="username" value="root" />
<property name="password" value="root" />

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="myAppDataSource" />

<bean id="service" class="Service.AppServiceImp">
<property name="jdbcTemplate" ref="jdbcTemplate" />

<property name="exceptionMappings">
<prop key="roseindia.exception.SpringException">

  • web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi=""
xmlns="" xmlns:web=""
id="WebApp_ID" version="2.5">



Download Source Code


Share on Google+Share on Google+

database spring registration form

Posted on: May 31, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: database spring registration form  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image