Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:12:44+00:00 2026-06-04T22:12:44+00:00

I am new to Spring and developing a dynamic web application in Spring and

  • 0

I am new to Spring and developing a dynamic web application in Spring and Tomcat and for some reason
I am not using Spring Security. I want to prevent users to access the login page who
are already in a session.Here is my code:

@Controller  
@RequestMapping("/login")  
@SessionAttributes("userAuthenticator")  
public class LoginController {  

    @RequestMapping(method = RequestMethod.GET)  
    public String showLogin(ModelMap model, HttpServletRequest request) {  
    System.out.println("Current Session: " + request.getSession(false));  

    if (request.getSession(false) == null) {  
    System.out.println("This means a new user wants to access the login page");  
    return "login";  
    }  

    else{  
    //means the user is already in session.So move him to another page say display.jsp  
    //actually I have done here with some other checking like getUserName() from   
    the model "UserAuthenticator" and if its again null redirect to login page.  
    }  

For Now forget about the else part.When I entered the URL in my browser
first time: …./AccountCreation/login.htm
Console Output:

Current Session: null  
This means a new user wants to access the login page  

Looks absolutely normal because a new user is accessing the page(login page also appears).

But when I re-enter the URL even refresh the page the console output comes:

Current Session: org.apache.catalina.session.StandardSessionFacade@511e0a  

Where did that session come from ?
(For that reason, in my else part I got:”The webpage has a redirected loop” in my browser)

Can anyone suggest me a way to achieve my goal without using Spring Security ?
This is very much needed for me now…..

Thanks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:12:44+00:00Added an answer on June 4, 2026 at 10:12 pm

    You can use a session variable.

    HttpSession ses=request.getSession(false);
    if(ses.getAttribute("sessionVar") == null)
         //show login page
    else
         // don't show login page
    

    Setting up session variable:

     HttpSession ses=request.getSession();
     ses.setAttribute("sessionVar","someValueToShowSession");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a web application using Spring JS and Dojo Toolkit. In this
I am using Spring Web MVC and Hibernate for developing my application. My login.jsp
I am developing a new web application with Struts2, Spring and Hibernate as its
I am developing my application using spring-web-mvc... Now at my Controller it returns like
I'm developing using IntelliJ 11u on a spring mvc application using tomcat. I tried
I am using Spring, Hibernate for developing my application. And as DB side, I
I am developing an application in Spring Web MVC where i need to execute
I am currently developing my project using Spring, Sutruts2 & Hibernate. Now i want
I developing a web application using GWT where i am trying to upload a
I'm developing a dynamic website using JSP & Spring MVC 3.0 and I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.