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 3698924
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:02:26+00:00 2026-05-19T05:02:26+00:00

I am creating a website using Java servlets, and I have a page called

  • 0

I am creating a website using Java servlets, and I have a page called LogIn. What I want to happen, is that once the user successfully fills out the login form, it returns them to the page that they were previously on.

Now this works fine with a GET or a POST from another page, because the previous page is stored in the Referer header. But when I redirect (302) to the LogIn page (from a page that a user cannot access because they are not logged in), the Referer header is null.

Is there any way to achieve what I want when the user is redirected to the LogIn page?

  • 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-05-19T05:02:27+00:00Added an answer on May 19, 2026 at 5:02 am

    I wouldn’t trust the referer header anyway since you’re dependent on the browser whether it’s been sent along. Rather supply it yourself based on the current request URI.

    response.sendRedirect("login?from=" + URLEncoder.encode(request.getRequestURI(), "UTF-8"));
    

    and then in the login form

    <form action="login" method="post">
        <input type="text" name="username">
        <input type="password" name="password">
        <input type="hidden" name="from" value="${param.from}">
        <input type="submit">
    </form>
    

    and then in the login action

    User user = userDAO.find(username, password);
    if (user != null) {
        session.setAttribute("user", user);
        response.sendRedirect(request.getParameter("from"));
    } else {
        request.setAttribute("error", "Unknown login");
        request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response);
    }
    

    Update: or if you want to be parameter-less (as per your comment on other answer), (ab)use the session.

    session.setAttribute("from", request.getRequestURI());
    response.sendRedirect("login");
    

    and then in the login action

    response.sendRedirect((String) session.getAttribute("from"));
    session.removeAttribute("from");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been tasked to develop an interactive website using java & mysql: using
I am considering creating my own website using Java and am trying to decide
I'm currently creating an auction website using asp and vb.net. I want to manipulate
I am creating an e-commerce website using OpenCart and hostgator for hosting. I want
I'm Creating a website for online reading stories using grails and i'm facing a
I am in the process of creating a Java program that goes on the
I'm creating a website using Entity Framework (4.1), which exposes WCF services, and I
Currently I am creating a website mainly using a mix of PHP, SQL, and
I am creating a website that connects to a windows program on the local
I was following instructions from a Java website ( http://java.sun.com/docs/books/tutorial/essential/io/file.html#createStream ) on creating or

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.