In this tutorial we will learn how to create and use custom Login page in spring authentication. User Details will be saved here in security XML file.

Technologies Used :

  • Spring Framework 3.1.1
  • Spring Security 3.1.0

Tools Used

  • Eclipse Indigo


1. Create Dynamic Web Project

Create dynamic web project by choosing  File >> New >> Other select “Dynamic Web Project” and select the name as “JBTSpringSecurityLogin” and click Finish. For Full details how to create project click here.

2. Adding Dependent Jars

It’s now time to ass all dependent jars in WEB-INF >> Jar Folder.

Required Jars would be

  • jstl-1.2.jar (Used for Tags in Login JSP)
  • org.springframework.aop-3.1.1.RELEASE.jar
  • org.springframework.asm-3.1.1.RELEASE.jar
  • org.springframework.beans-3.1.1.RELEASE.jar
  • org.springframework.context-3.1.1.RELEASE.jar
  • org.springframework.core-3.1.1.RELEASE.jar
  • org.springframework.expression-3.1.1.RELEASE.jar
  • org.springframework.web-3.1.1.RELEASE.jar
  • org.springframework.web.servlet-3.1.1.RELEASE.jar
  • spring-security-config-3.1.0.RELEASE.jar
  • spring-security-core-3.1.0.RELEASE.jar
  • spring-security-web-3.1.0.RELEASE.jar
  • aopalliance-1.0.jar


3. Configure Web.XML

Now need to configure application to forward all request to pass through Spring framework and through Spring Security.

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

		<param-value>classpath:applicationContext-security.xml	</param-value>




4.  Configuring Spring Security

Here we will configure which part of the appication should be secured and which part shouldn’t be. Also here we will configure our customize Login and logout page.

<?xml version="1.0" encoding="UTF-8"?>

<b:beans xmlns=""
	xmlns:b="" xmlns:xsi=""

	<http pattern="/logout.jsp" security="none" />
	<http pattern="/login.jsp" security="none" />
	<http pattern="/img/**" security="none" />
	<http pattern="/css/**" security="none" />

	<http realm="Contacts Realm">
		<intercept-url pattern="/**" access="ROLE_USER" />
		<form-login login-page="/login.jsp"
			default-target-url="/index.jsp" />
		<logout logout-success-url="/logout.jsp" logout-url="/logout"
			invalidate-session="true" />
		<remember-me />

			<!-- <password-encoder hash="md5"/> -->
				<user name="vivek" authorities="ROLE_USER" password="password" />


Now if we try to access “http://localhost:8080/JBTSpringSecurityLogin/index.jsp” Custom Login page will be displayed

Here you can see customize login page got displayed instead of Spring Provided Login page and user is authenticated against the credential available in XML file itself.

To get the code of this application click here

3 thoughts

  1. Admin I’ve tried copying the .war file in webapps folder of Apache Tomcat 5.5 and tried the URL in my browser. But I’m sorry this didn’t work. Can you help me please?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top