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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:58:15+00:00 2026-05-24T23:58:15+00:00

I want to store a variable in session data, in a servlet. The servlet

  • 0

I want to store a variable in session data, in a servlet. The servlet redirects the user to a 3rd party site, and from the 3rd party site user is sent to JSP page in same web app. I want to access a session variable stored by servlet (before redirection to 3rd party site) in the JSP. How do I store such an object in servlet? And how do I access that object from JSP file?

  • 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-24T23:58:16+00:00Added an answer on May 24, 2026 at 11:58 pm

    You just need to make sure that the callback request instructs the server somehow to use the same session as the initial request. Normally, this is to be done by setting the session cookie in the request header. But a 3rd party site isn’t going to do that. However, the Servlet API offers you the possibility to identify the session by the JSESSIONID fragment in the URL.

    So if you construct your callback URL like follows,

    HttpSession session = request.getSession();
    session.setAttribute("someName", someObject);
    
    String callbackURL = "http://yourhost.com/callback.jsp;JSESSIONID=" + session.getId();
    String redirectURL = "http://otherhost.com/process?callbackURL=" + URLEncoder.encode(callbackURL, "UTF-8");
    
    response.sendRedirect(redirectURL);
    

    This way the callback.jsp will have access to the same session and thus also all stored attributes. By the way, you should really use a servlet with doGet() here, preprocessing Java code doesn’t belong in a JSP.


    Apart from the concrete question, there’s another way to achieve this: store the information of interest in the application scope by a long, auto-generated and unique key (e.g. java.util.UUID) and add it as request parameter to the callback URL. When the callback is to be processed, just obtain it from application scope instead of session scope. This is usually to be done inside a popup window which refreshes the parent window and closes itself after successfully processing the callback by JavaScript. This way you don’t need to worry about the session.

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

Sidebar

Related Questions

I want to store the current URL in a session variable to reference the
hi i want to store textfield data in a variable but my code is
I have login page, once logged in I create a session variable to store
I want to store a URL prefix in an Windows environment variable. The ampersands
I want to store certain items in the database with variable amount of properties.
I want to store a $ character in a PHP variable. $var = pas$wd;
I want to store the data returned by $_SERVER[REMOTE_ADDR] in PHP into a DB
I'm planning to use some session variables on an intranet ASP/VB.NET page, and want
I want to know how to use PHP session variable in zend framework here
Say I want to store some variable in my controller. I want to initialize

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.