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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:48:29+00:00 2026-05-20T15:48:29+00:00

In my JSP webapp, i want to validate that a user is coming from

  • 0

In my JSP webapp, i want to validate that a user is coming from a specific page of mine, http://myapplication.com/foo.jsp. On the page doing the checking, I could do:

String ref = request.getHeader("referer");

Then compare ref to http://myapplication.com/foo.jsp

However, this validation can be easily spoofed. What are some other techniques to verify that a client is coming from an expected URL?

I imagine this has come up before in SO.
Thanks

PR

  • 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-20T15:48:30+00:00Added an answer on May 20, 2026 at 3:48 pm

    Let the preprocessing servlet of the first JSP generate an unique token.

    String token = UUID.randomUUID().toString();
    

    Store this in session

    session.setAttribute("token", token);
    

    Pass it as hidden input value of the form

    <input type="hidden" name="token" value="${token}" />
    

    or as a request parameter of the link when you’re using links instead of forms

    <a href="second.jsp?token=${token}">link</a>
    

    Let the preprocessing servlet of the second JSP compare it with the one in the session

    String token = (String) session.getAttribute("token");
    session.removeAttribute("token");
    
    if (token != null && token.equals(request.getParameter("token"))) {
        // Valid, continue requesst.
    } else {
        // Invalid, block request.
    }
    

    That was the basic concept which assumes a single page-to-page conversation. To cover multiple browser pages/tabs you’d like to use Set<String> or maybe Map<String, Set<String>> as token instead (with URIs as keys and tokens as values).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In JSP, I notice that I can't render ${} into HTML. After the page
On my JSP page, I defined some javascript with a variable that get value
I am developing a java webapp, using jsp/jquery/ejb/jboss. I have a web-form that enables
I wrote custom servlet in Liferay and want to know which user page calls
I'm using a jsp file as a model from a Controller and I want
In my JSF 1.2 webapp I have a page with a <h:commandButton> that invokes
I have created a simple JSP file that I want to deploy in Jetty
I have a webapp in Tomcat with a main JSP file that includes another
I have one jsp site under webapps/ROOT of tomcat (accessible by doing http://localhost:8080)and want
I want user to provide login + password to login to my webapp. If

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.