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

Spring Login Example

In this section , we have shown a simple Spring loging Example. In this example, we have accepted two values Username and password. We have created Logger.java and declared two private variables username and password than we have created setter getter method. Now create UserLogin.java. This class controls login request by bean properties

Ads

Tutorials   
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
Ads

Spring Login Example

In this section , we have shown a simple Spring loging Example. In this example, we have accepted two values Username and password. We have created Logger.java and declared two private variables username and password than we have created setter getter method. Now create UserLogin.java. This class controls login request by bean properties Than we create dispatcher-servlet.xml to handle all bean configuration. After this we create a web.xml file to handle all DispatcherServlet. Than we create jsp page table.jsp and have defined two text fields and one button. You  can download this example directly and run it in your console/eclipse.

Following is the Simple Spring Login Example:

  1. Logger.java
  2. UserLogin.java
  3. dispatcher-servlet.xml
  4. web.xml
  5. table.jsp
  6. TableView.jsp
  7. index.jsp

This video tutorial is made using the Spring Framework 2.5 and you will learn to make form in Spring MVC. Following is the links of the similar tutorial develop using the latest version of Spring MVC:

Above are the latest tutorials of Spring MVC Login form.

Following video instruction teaches you how to download and run the code of this example from Eclipse IDE. Eclipse IDE and Tomcat server is required to run this program.

Video Tutorial: How to create Spring MVC Login Form? 

Logger.java

package roseindia.model;

public class Logger {
	private String userName;
	private String password;

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

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

}

UserLogin.java

package roseindia.SpringController;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import roseindia.model.Logger;


@Controller
public class UserLogin{
	@RequestMapping("/load-form.html")
	public String loadForm(Model model, Logger field) {
		model.addAttribute("field", field);
		return "table";
	}

	@RequestMapping("/process-form.html")
	public String processForm(Model model, Logger field) {
		model.addAttribute("field", field);
		return "TableView";
	}
}

dispatcher-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:component-scan base-package="roseindia.SpringController" />
<bean id="viewReslover"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/view/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SpringWebExample</display-name>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

table.jsp

<[email protected] prefix="form" uri="http://www.springframework.org/tags/form"%>
<html>
<head>
<title>My Form table</title>
</head>
<body>
<form:form commandName="field" action="process-form.html">
<table cellpadding="5" cellspacing="5">
<tr>
<td>UserName</td>
<td><form:input path="UserName" /></td>
</tr>

<tr>
<td>Password</td>
<td><form:password path="Password" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Login" /></td>
</tr>
</table>
</form:form>
</body>
</html>

TableView.jsp

<H1 align="center">Welcome Roseindia.net</H1>
UserName:- ${field.userName}<br/>
Password:- ${field.password}<br/></pre>

index.jsp

<%
response.sendRedirect("load-form.html");
%>

Output

When you will enter username and password into the respective field and then if you click on login button then the output will be as follows :

Updated Source code: Download the Source code in Eclipse Project format.

Download Source Code

Download required jar files for this example

Advertisements

Share on Google+Share on Google+

Spring Login Example

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

Advertisements

 

Discuss: Spring Login Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
conqueror
May 28, 2013
where is this ? >:/

load-form.html where is this page !! thx.

Ads

 

Ads