Solved

Applet to Servlet session fails

Posted on 2004-04-23
10
744 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Jquery ajax file upload not working 11 172
build fail in maven project 11 186
maven project jars 7 53
HTTPSessionBindingListernter not configured in deployment descriptor 2 53
If you thought ransomware was bad, think again! Doxware has the potential to be even more damaging.
This problem is more common than not and I will show you some things to check to solve this problem.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 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