Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
SPRING COOKBOOK

You're reading from   SPRING COOKBOOK Over 100 hands-on recipes to build Spring web applications easily and efficiently

Arrow left icon
Product type Paperback
Published in May 2015
Publisher Packt
ISBN-13 9781783985807
Length 234 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Murat Yilmaz Murat Yilmaz
Author Profile Icon Murat Yilmaz
Murat Yilmaz
Jerome Jaglale Jerome Jaglale
Author Profile Icon Jerome Jaglale
Jerome Jaglale
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Creating a Spring Application FREE CHAPTER 2. Defining Beans and Using Dependency Injection 3. Using Controllers and Views 4. Querying a Database 5. Using Forms 6. Managing Security 7. Unit Testing 8. Running Batch Jobs 9. Handling Mobiles and Tablets 10. Connecting to Facebook and Twitter 11. Using the Java RMI, HTTP Invoker, Hessian, and REST 12. Using Aspect-oriented Programming Index

Authenticating users using a custom login page


In this recipe, you'll learn how to build your own login form instead of using Spring's default login form.

How to do it…

Here are the steps to define a custom login page:

  1. Make sure that the JSTL Maven dependency is declared in pom.xml:

    <dependency> 
        <groupId>javax.servlet</groupId> 
        <artifactId>jstl</artifactId> 
        <version>1.2</version> 
    </dependency> 
  2. Make sure that a JSP view resolver is declared in the AppConfig class:

    @Bean 
    public ViewResolver jspViewResolver(){ 
        InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 
        resolver.setViewClass(JstlView.class); 
        resolver.setPrefix("/WEB-INF/jsp/"); 
        resolver.setSuffix(".jsp"); 
        return resolver; 
    } 
  3. Add a controller method for the login page in a controller class:

    @Controller
    public class UserController {
    
      @RequestMapping("login") 
      public String login() { 
          return "login"; 
      }
    … 
  4. Add a JSP for...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image