Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Carry a JSP session variable to an applet?

Status
Not open for further replies.

gerald

Programmer
Apr 10, 2000
152
US
Hi there. :)
Well I am well on my way to completing my chat system. I am now at the point of actually trying to integrate it with the rest of my system which uses mostly JSP and servlets.

My question is this:

Right now a user can login through a JSP page to my site where he can enter different parts such as the chat rooms and the message boards and games. I am using a JSP session variable to carry my user information from page to page.

Is there an easy way to access that session variable from inside an applet? Or maybe from the server if I pass the session ID to the applet as a PARAM value and send it to the server from the applet?

 
I think, the most simple way is the LiveConnect. You can call the public mothods of an applet and this way you can pass easy the session variable.
But, the PARAM tag is a good solution, too:

XXX.jsp file:
<APPLET CODE=XXX.class WIDTH=100 HEIGHT=100>
<PARAM NAME=&quot;SESSION&quot; VALUE&quot;<%= session.getId() %>&quot;>
</APPLET>

XXX.java file (applet):
...
String sessionId=getParameter(&quot;SESSION&quot;);
...

Bye, Otto.
 
Well I knew how to pass the session ID, I just dont know how to actually grab the session attributes from a non-JSP/servlet context. I think somehow I need to have my chat server interact with the web container somehow.

In the meantime I have a little workaround that works fine.

What I do is, in the JSP page that calls the applet I kinda create my own cheapy session.

I create a file with a random file name of between 20-30 characters. In that file I just store the userid of the person that is logged on. Then I pass the filename to the applet with a PARAM value set to the filename and another PARAM value with the userid.

When the chat applet is invoked, it sends a message to the chat server indicating that a new user is logging on, and sends the session ID and userid with it.

The server then reads the temporary file, and gets the user id. First it checks that the userid matches the userid that was sent by the applet, thus making the session id like a 1-time password. Then it pulls the user information from the database and sends it all back to the chat applet(except for the real password which the applet doesnt really need to know and would be insecure to transfer it that way). The applet then creates a user object with the correct information and I am on my way. :)

Crude and not extremely secure but it is a temporary fix that will let me get on with my project for the time being. hehe

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top