Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Applet to Servlet session fails

Posted on 2004-04-23
10
Medium Priority
?
753 Views
Last Modified: 2008-03-10
Hi,
I have a JSP page with an applet in it. The applet talks to a Servlet. The session object that is present in my JSP page is not accessable in my servlet.
How can I get the session object from my JSP page to the Servlet through an Applet?

Thanks
Uma
0
Comment
Question by:umajava
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
10 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 200 total points
ID: 10897257
You can pass the sessionid to the applet as a parameter:

  <parameter name="sess" value="<%= "" + session.getId() %>"/>

Then, you should be able to put the session into the servlet connection in the applet:

   servletConnection.setRequestProperty( "cookie", sess ) ;

Any good?

Tim
0
 

Author Comment

by:umajava
ID: 10897312
what is servletConnection? where should I call this
servletConnection.setRequestProperty( "cookie", sess ) ;

in my applet? How do I get the session in my servlet?
0
 

Author Comment

by:umajava
ID: 10897344
one more thing is that, this problem is having only for the first time when I log in. As soon as my session in null, I am redirected to the login page again. If I login again using the same browser, now everything works fine.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 35

Expert Comment

by:TimYates
ID: 10897722
> in my applet?

I guess you create a URLConnection to your servlet (from inside the applet)?

There is where you set the session id

> How do I get the session in my servlet?

  public void doPost( HttpServletRequest req, HttpServletResponse res )
  {
      HttpSession session = req.getSession() ;
0
 
LVL 28

Expert Comment

by:rrz
ID: 10900405
To use Tim's idea, maybe you could try
<parameter name="sess" value="<%= "jsessionid=" + session.getId() %>"/>    
0
 
LVL 35

Expert Comment

by:TimYates
ID: 10900417
Or maybe add

servletConnection.setRequestProperty( "jsessionid", sess ) ;

as well as

servletConnection.setRequestProperty( "cookie", sess ) ;

Though this isn't necessary in my code...
0
 
LVL 28

Expert Comment

by:rrz
ID: 10900522
or just add the jsessionid as extra path info  on the url
0
 

Author Comment

by:umajava
ID: 10905918
Tim
I will try this idea and get back to you.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Tech spooks aren't just for those who are tech savvy, it also happens to those of us running a business. Check out the top tech spooks for business owners.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question