Solved

Applet to Servlet session fails

Posted on 2004-04-23
10
743 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In the hope of saving someone else's sanity... About a year ago we bought a Cisco 1921 router with two ADSL/VDSL EHWIC cards to load balance local network traffic over the two broadband lines we have, but we couldn't get the routing to work consi…
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now