This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes How is jsessionId handled when moving from http --> https? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How is jsessionId handled when moving from http --> https?" Watch "How is jsessionId handled when moving from http --> https?" New topic
Author

How is jsessionId handled when moving from http --> https?

Rex Norm
Ranch Hand

Joined: Dec 11, 2010
Posts: 41
Let's say that I've never visited a site, and I go to it using http://mysite.com.

The servlet container is supposed to assign a jsessionId and try to set a cookie. If I have cookies enabled, I should no longer see the jsessionId, correct?

Now, what happens when I redirect (or forward) from a page on http://mysite.com/servlet1 to another https://mysite.com/servlet2? Will URL rewriting kick in? Will the SAME sessionId be used (and is this good practice in terms of security?)

If URL rewriting does kick in for the scheme change (http --> https), should i expect it to break my URLs by adding the ";jsessionId=xxxx"? and what can I do to prevent this? (servlet filter to intercept and strip this out)?

I would even appreciate an RTFM reference if this is too basic.

thanks in advance.

_R
Rex Norm
Ranch Hand

Joined: Dec 11, 2010
Posts: 41
Sorry one more question to be complete-- is the behavior different when coming from https:// and redirecting (or forwarding??) to http://?

that is, is jsessionID (URL rewriting) used in the reverse direction or can the cookie be used? Can I force this?

thanks,

_r
Mike Zal
Ranch Hand

Joined: May 04, 2011
Posts: 144

You should never perform url rewriting yourself since they container can do it if you tell it to. If you are creating URLs in a Servlet, you should use the javax.servlet.http.HttpServletRequest encodeURL method. In a JSP you should use the JSTL url tag <c:url> example. These will automatically perform url rewriting if needed. If you use encodeURL or url tags anytime you have a link then you should be set.


OCJP6, OCWCD5
Rex Norm
Ranch Hand

Joined: Dec 11, 2010
Posts: 41
Mike, thanks for your response.

You should never perform url rewriting


I plan to avoid this.

If you are creating URLs in a Servlet, ...

yes, this is my intent... I need to redirect from an insecure page to a secure login page (SSL) and then redirect to another secure page on success.
...you should use the javax.servlet.http.HttpServletRequest encodeURL method. In a JSP you should use the JSTL url tag <c:url> example.

So does this mean that the same sessionId is used for both http and https? Meaning that a redirect from http --> https will be handled by the tag and container? I seemed to read somewhere that setting a new sessionId is a good idea for the secure component. I guess nothing is preventing me from setting a new cookie with a new (self generated) ID with quick expiration for the secure part and relying on that, right?

Also, is there a difference between <html:link> and <c:url>? do they do the same thing?


thanks for your help.
_R
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60755
    
  65

<html:link> is a proprietary struts tag.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How is jsessionId handled when moving from http --> https?
 
Similar Threads
Session
Head First Problem
http - https - load balancer - web Server - app Server
Session ID conveyed as part of URL
sharing session state between https and http