In spring boot, we see how to redirect to a different dashboard page after successful login instead of previous page. The redirection is always to the dashboard page after the login in spring boot.

When a user accesses a website url in Spring boot application, the user is redirected to a login page for authentication. After successful login, the user is redirected to the previous page by default. In some cases redirecting to previous page is not recommended. Alternatively, you want to switch to a default dashboard page.

When developing a simple application with simple login page, the user is expected to see the dashboard after a successful login. The specific type of applications are expected to access the pages only after the successful login. These software are designed to navigate the respective pages after the user has landed on the dashboard. In that case, redirecting to the previous page is not the ideal solution.

Here, this post will demonstrate how to switch to a dashboard page regardless of where the user originates from.

Step 1 – pom.xml file dependency

Create a new spring boot security application with “spring-boot-starter-web” and “spring-boot-starter-security“. The web dependency adds the dependent jars for the web application. The security jar will add all security-related modules. 

The pom.xml file will look as like the one below

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""
		<relativePath /> <!-- lookup parent from repository -->
	<description>Spring Boot Project</description>







Step 2 – Configure Jsp Pages

Create Jsp pages to render login page and dashboard pages. To invoke the jsp page in the spring boot application, add the configuration in the and then add the respective jsp files to the “src/main/webapp/WEB-INF/jsp” folder.



<h1>Welcome to Spring Boot Simple Security Example</h1>
<a href="/logout">logout</a>


<h1>Welcome to Spring Boot Security</h1>

<form method="POST" action="/login">
	User Name : <input type="text" name="username" value="user"/><br><br>
	Password  : <input type="password" name="password" value="password"/><br><br>
	<input type="submit" name="submit"/>


<h1>Welcome to Spring Boot DashBoard</h1>

<h2>You are in Spring Boot DashBoard Page</h2>
<br><a href="/logout">logout</a>

Step 3 – Configure Controller class

Create a controller class to invoke a jsp page. Create 3 urls, default url, login url, and dashboard url. The default url will invoke the home.jsp that displays the default page. The control will be redirected to the URL login page for authentication. After a successful login, the dashboard url will be used to redirect.

The code below shows the controller class.

package com.yawintutor;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

public class TestController {
	public ModelAndView defaultHome() {
		return new ModelAndView("home");

	public ModelAndView login() {
		return new ModelAndView("login");

	public ModelAndView dashboard() {
		return new ModelAndView("dashboard");

Step 4 – Spring Boot Security configuration

The spring boot security module supports redirecting to the dashboard page after all successful login. The api “defaultSuccessUrl” is used to redirect to the dashboard page. The following spring boot security configuration file shows how to configure the redirect.  The second parameter “true” tells you to always redirect your spring boot security to this page.

package com.yawintutor;

import org.springframework.context.annotation.Configuration;

public class SpringBootSecurityConfiguration extends WebSecurityConfigurerAdapter {
	public void configure(AuthenticationManagerBuilder auth) throws Exception {

	public void configure(HttpSecurity http) throws Exception {

We saw in this post that the default SuccessUrl api call helps to redirect to the Dashboard page from whatever the user.

Leave a Reply