Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

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.


Spring 4 Introduction and example Features of Spring Framework 5 How to make Spring web Login form? How to make Simple form in Spring web? Spring, Hibernate login and registration application Spring Framework Tutorial for beginners with examples Spring Framework for Apache Hadoop 2.3.0 GA released Spring Framework 4.1 GA is released with major features Why to use Spring Framework? Spring Framework 4.1 - First Release candidate available Spring IO Platform 1.0.0 Released Spring 4: Login Form using Spring MVC and Hibernate Example Spring 4 MVC Login form Example with source code Spring 4 MVC Hello World Example: Spring 4 MVC Tutorial will full source code Spring Web MVC Application Error:ClassNotFoundException: DispatcherServlet on deploying Features of Spring 4 Spring Framework 4.0 released Spring Framework 4: Spring Framework 4 Tutorials and Example Spring Integration 3.0 Release is released and available for download Spring Tutorial for Beginners Java Springs Framework Tutorial Spring Architecture Spring Framework Tutorials database spring registration form Spring Login Example Roseindia Spring Tutorial Spring Tutorial Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration

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.

<[email protected] 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


Online Training Classes

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