aspose file tools*
The moose likes Servlets and the fly likes Session in an application having html,servlets,Jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session in an application having html,servlets,Jsp" Watch "Session in an application having html,servlets,Jsp" New topic
Author

Session in an application having html,servlets,Jsp

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Hi,

I have a web application having servlets,jsp,html pages....

Scenario 1:

How can i guarantee session across the application,if the user moves

across jsp pages ,servlets and html pages ..?

Scenario 2:

If cookies are disabled then?

Thanks in advance,
Regards
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Use URL rewriting and set/get the necessary info into the session (getSession, session.setAttribute,session.getAttribute...).


[My Blog]
All roads lead to JavaRanch
Chetan Raju
Ranch Hand

Joined: Aug 02, 2006
Posts: 109
Use

1. URL Rewriting
2. HTTP Session API
3. Form Based
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Thanks for the quick response...

But if the cookies are disabled...then will the html pages cause a problem if i go for URL rewriting...

in terms of keeeping the session intact

Regards
[ September 27, 2006: Message edited by: A Kumar ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
In case of cookies disabled , go for URL rewriting.


Rahul Bhattacharjee
LinkedIn - Blog
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

As Raul mentioned.
If cookies are disabled, you'll need to use URL Rewriting.

If this is the case, you'll need to convert all of your HTML pages to JSPs so that you can embed the sessionId into all of the URLs used in anchor tags and form actions.

[correction]
You'll need to convert any HTML pages that have links or forms to JSPs.
[ September 27, 2006: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
You'll need to convert any HTML pages that have links or forms to JSPs.



This is the clarification I needed .....

Regards
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
You have to rewrite the jsp and servlet using some different set of methods which incluses the jsessionid after the url.All the hrefs in your jsps will also change.

Lots of online materials are also available describing this method.even Head first book on servlets and jsp has delt with this , in the session tracking chapter.
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Yes Rahul...

You need to use encodeURL(...)

but I was concerned about the HTML pages in such an evironment...

Regards
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
I can think of two things in this regard,

Basically session is tracked using JSESSIONID in cookies and cookies which traverses to and fro in the header of the HTTP request and responses.So in case the html is forward by a servelt then the header of the HTTP response that has the html would also contain the JSESSIONID.In that way the session can be tracked for html pages.

Or,

you have append every anchor tag's href attribute with something like
;JSESSIONID=<sessionID> to maintain the session for html pages.

I think this needs a lot of work.Prefered way would be to certify your application for browsers with cookies enabled.this way you can reduce a lot of work.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Session in an application having html,servlets,Jsp