Solved

Applet to Servlet session fails

Posted on 2004-04-23
10
746 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
  • 3
  • 3
  • 2
10 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 50 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 27

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 27

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Riverbed Technology's webinar discusses networking for the cloud era with simplified SD-WAN cloud connectivity.
Ransomware is a malware that is again in the list of security  concerns. Not only for companies, but also for Government security and  even at personal use. IT departments should be aware and have the right  knowledge to how to fight it.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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