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 JSP/form/servlet - session persistence ? 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 "JSP/form/servlet - session persistence ?" Watch "JSP/form/servlet - session persistence ?" New topic
Author

JSP/form/servlet - session persistence ?

Louis Cypher
Greenhorn

Joined: Mar 26, 2009
Posts: 3
Hello,

a JSP page contains a from that, when submitted calls a servlet (specified in the action attribute) that sets an attribute in the session scope and gets back to the jsp page ( it besides the form contains a few jstl tags that display the data entered in the form.)

Now, when cookies are enabled, everything works fine, but when they are not, I can't figure out how to maintain a single session across jsp -> servlet -> back to jsp

What is the best practice approach in my case ?

Regards!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

URL rewriting.
Louis Cypher
Greenhorn

Joined: Mar 26, 2009
Posts: 3
URL rewriting is what I'm trying to introduce but how do I send a sessionid back to jsp ?

Something like :

String url = response.encodeURL("page.jsp");
RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
rd.forward(request,response);

?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

http://onjava.com/pub/a/pub/a/onjava/2002/05/08/jstl.html?page=2
Louis Cypher
Greenhorn

Joined: Mar 26, 2009
Posts: 3
I think I got it :

<c:url var="url" value="servletURL" />
<form action="${url}" method= ......

in the jsp will do the job.

Please correct me if I'm wrong or suggest a more convenient way ( if any) to achieve the same ...

Regards,
Louis
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Nope, that's about it. You could use the url tag inside the form tag "action" attribute, but that can look a little messy-matter of preference.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JSP/form/servlet - session persistence ?
 
Similar Threads
How good is PRG (POST/REDIRECT/GET) pattern in avoiding duplicate form submission?
java.lang.NullPointerException
Doubt in request.getSession(boolean) !
jsp page contents..
I can't use application and session to store data