how to get a sessionId from the jsp to applet

Upload core product.
raychamp
Posts: 18
Joined: Wed May 12, 2010 2:03 pm

how to get a sessionId from the jsp to applet

Post by raychamp »

Hello everyone,
I have a bit of a problem. I am trying to preserve the sessionId created when I connect to the server. For instance, I have sessionId=123qwe in some.jsp. The JfileUpload applet is embedded in some.jsp. When I try to use the sessionId from some.jsp, it has changed/created another sessionI. Somehow I have lost my previous session.

Does anyone know why this happens or think of a solution?

I have tried using the solution in the FAQ, but it is not very clear on how to do this? :?

raychamp
Posts: 18
Joined: Wed May 12, 2010 2:03 pm

Re: how to get a sessionId from the jsp to applet

Post by raychamp »

Let me try to be more clear. I am creating a session variable of username when user logs in. I am using the JSESSIONID that is sent from the server when the user firsts logs in. When I get to the jsp with the JFileUPload applet in it, the applet gets another JSESSIONID from the server and the previous session varaible is no longer available and I need it to create a specific directory to store the uploaded files.

Any ideas???

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: how to get a sessionId from the jsp to applet

Post by support »

Yes, the following tutorial should help:
http://www.jfileupload.com/products/jfi ... ation.html

raychamp
Posts: 18
Joined: Wed May 12, 2010 2:03 pm

Re: how to get a sessionId from the jsp to applet

Post by raychamp »

OK, I tried both methods and still I can't access the JSESSIONID from the initial request.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: how to get a sessionId from the jsp to applet

Post by support »

You mean that you have a JSP and in this JSP you cannot get ID of HTTPSession?

Code: Select all

<% 
HttpSession sessionJava = request.getSession();
String id = sessionJava.getId();
...
%>
Then pass the JSESSIONID either in URL or in cookie.
Are you sure session is enabled in process.jsp?

Which version of Tomcat are you using?

raychamp
Posts: 18
Joined: Wed May 12, 2010 2:03 pm

Re: how to get a sessionId from the jsp to applet

Post by raychamp »

No, I can get the ID of the HTTPSession from the fileupload.jsp. The jfileupload applet is embedded in this fileupload.jsp and when I invoke it from the jsp it gets its own session ID. It then uploads the files as it supposed to do. But I want to build a directory to store these files in using the username/datetime from the fileupload.jsp session ID. The directroy is being built in the process.jsp, which is invoked from the applet_http.js and thus has the wrong session ID.
I am scrambling to understand sessions right to try and figure this out. Maybe my algorithm/logic is wrong.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: how to get a sessionId from the jsp to applet

Post by support »

Can you dump the HTTP request sent by JFileUpload? Then you can see if JSESSIONID is really sent and is correct. To do so, in process.jsp you can ads something like:

Code: Select all

<%
  System.out.println("---------- Date :"+new Date());
  String smethod = request.getMethod();
  System.out.println("Method :"+smethod);
  System.out.println("URI :"+request.getRequestURI());
  System.out.println("URL :"+request.getRequestURL());
  System.out.println("Path :"+request.getPathInfo());
  System.out.println("Pro :"+request.getProtocol());
  System.out.println("Query :"+request.getQueryString());
  System.out.println("Scheme :"+request.getScheme());
  

  Enumeration en = request.getHeaderNames();
  while (en.hasMoreElements())
  {
    String el = (String) en.nextElement();  
    System.out.println("Head:"+el+"="+request.getHeader(el));
  }
  System.out.println("Cookies :");
  Cookie[] cookies = request.getCookies();
  if (cookies != null)
  {
  	for (int i=0;i<cookies.length;i++)
  	{
  		System.out.println(cookies[i].getName()+"="+cookies[i].getValue());
  	}
  
  }
  en = request.getParameterNames();
  while (en.hasMoreElements())
  {
    String el = (String) en.nextElement();  
    System.out.println("Param:"+el+"="+request.getParameter(el));
  }

raychamp
Posts: 18
Joined: Wed May 12, 2010 2:03 pm

Re: how to get a sessionId from the jsp to applet

Post by raychamp »

This is what I am getting in my IDE console output.

Session id in LoginAction: 6783F5E5CEF84908374743F9FF9E162A
Session id in Login: 6783F5E5CEF84908374743F9FF9E162A
In LoginService
Session id in sssp.jsp6783F5E5CEF84908374743F9FF9E162A
userLogin = ray
Session id in fileupload.jsp6783F5E5CEF84908374743F9FF9E162A
userLogin = ray
in process.jsp
in setting userlogin is true ray
---------- Date :Wed May 26 10:18:13 CDT 2010
Method :GET
URI :/CmeJfileUploadDemo/fileupload.jsp
URL :http://localhost:8087/CmeJfileUploadDemo/fileupload.jsp
Path :null
Pro :HTTP/1.1
Query :null
Scheme :http
Head:accept=image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Head:referer=http://localhost:8087/CmeJfileUploadDemo/login.do
Head:accept-language=en-us
Head:user-agent=Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; OfficeLiveConnector.1.4; .NET CLR 3.5.30729; .NET CLR 3.0.30729; OfficeLivePatch.1.3)
Head:accept-encoding=gzip, deflate
Head:host=localhost:8087
Head:connection=Keep-Alive
Head:cookie=JSESSIONID=6783F5E5CEF84908374743F9FF9E162A
Cookies :
JSESSIONID=6783F5E5CEF84908374743F9FF9E162A
Session id in process.jsp6783F5E5CEF84908374743F9FF9E162A
userLogin = ray
**********************************************************************************
This is before I drop files into jfileupload applet in fileupload.jsp

*********************************************************************************
First file
**************************
user login is null null
---------- Date :Wed May 26 10:18:44 CDT 2010
Method :POST
URI :/CmeJfileUploadDemo/process.jsp
URL :http://localhost:8087/CmeJfileUploadDemo/process.jsp
Path :null
Pro :HTTP/1.1
Query :null
Scheme :http
Head:user-agent=JFileUpload
Head:host=localhost:8087
Head:cookie=JSESSIONID=abc123
Head:content-length=58449
Head:content-type=multipart/form-data; boundary=caiiX-37OrEc1hFctBehI2G0DoWxub9C-MKi
Cookies :
JSESSIONID=abc123
Session id in process.jspBF69A12698F69C5844DAC656F19E4444
userLogin = null
user login is null null
**************************
second file
***************************
---------- Date :Wed May 26 10:18:44 CDT 2010
Method :POST
URI :/CmeJfileUploadDemo/process.jsp
URL :http://localhost:8087/CmeJfileUploadDemo/process.jsp
Path :null
Pro :HTTP/1.1
Query :null
Scheme :http
Head:user-agent=JFileUpload
Head:host=localhost:8087
Head:cookie=JSESSIONID=BF69A12698F69C5844DAC656F19E4444
Head:content-length=127756
Head:content-type=multipart/form-data; boundary=i5_TDqRrnU-28yXeIJDOXWk-EFrYwmtoOJwl
Cookies :
JSESSIONID=BF69A12698F69C5844DAC656F19E4444
JSESSIONID=abc123
Session id in process.jspBF69A12698F69C5844DAC656F19E4444
userLogin = null
user login is null null
***************************
thirdfile
***************************
---------- Date :Wed May 26 10:18:44 CDT 2010
Method :POST
URI :/CmeJfileUploadDemo/process.jsp
URL :http://localhost:8087/CmeJfileUploadDemo/process.jsp
Path :null
Pro :HTTP/1.1
Query :null
Scheme :http
Head:user-agent=JFileUpload
Head:host=localhost:8087
Head:cookie=JSESSIONID=BF69A12698F69C5844DAC656F19E4444
Head:content-length=724917
Head:content-type=multipart/form-data; boundary=Unj2VOFLr6DRncxGK9PeZufjJViomnVCSl6P0A
Cookies :
JSESSIONID=BF69A12698F69C5844DAC656F19E4444
JSESSIONID=abc123
Session id in process.jspBF69A12698F69C5844DAC656F19E4444
userLogin = null
user login is null null
***********************************
fourth file
************************************
---------- Date :Wed May 26 10:18:44 CDT 2010
Method :POST
URI :/CmeJfileUploadDemo/process.jsp
URL :http://localhost:8087/CmeJfileUploadDemo/process.jsp
Path :null
Pro :HTTP/1.1
Query :null
Scheme :http
Head:user-agent=JFileUpload
Head:host=localhost:8087
Head:cookie=JSESSIONID=BF69A12698F69C5844DAC656F19E4444
Head:content-length=194841
Head:content-type=multipart/form-data; boundary=3QvH2bFAMkz7wCPp6uoCdGnuqCMnNJDG
Cookies :
JSESSIONID=BF69A12698F69C5844DAC656F19E4444
JSESSIONID=abc123
Session id in process.jspBF69A12698F69C5844DAC656F19E4444
userLogin = null

raychamp
Posts: 18
Joined: Wed May 12, 2010 2:03 pm

Re: how to get a sessionId from the jsp to applet

Post by raychamp »

I don't understand how hardcoding the jsessionid into the url will help maintain session between the applet running in the browser and the process.jsp on the server.

User avatar
support
Posts: 1503
Joined: Sun Jan 27, 2008 6:19 pm

Re: how to get a sessionId from the jsp to applet

Post by support »

HTTPSession can be maintained in two ways with JSP:
Solution 1: JSESSIONID as cookie
Solution 2: jsessionid in URL for URLRewriting. What is important is to use ";" and not "?":
http://yourserver.com/process.jsp;jsessionid=abc123
Solution 2 was designed for browsers where cookie support has been disabled.

Your logs reports that a new JSESSIONID is generated. JSESSIONID becomes multivalued. Could you check path used in the JSESSIONID cookie?
I think you need something like:
<PARAM NAME="param8" VALUE="cookiepath">
<PARAM NAME="value8" VALUE="/webapp">

You can dump cookie info with HTTPFox add-on in FireFox.

Also, could you tell me what you have in scope field in process.jsp at

Code: Select all

<jsp:useBean id="upBean" scope="page" class="jfileupload.jspupload.FileUploadBean">
It needs to be updated to scope="session".

Post Reply