Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP/form/servlet - session persistence ?

 
Louis Cypher
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
URL rewriting.
 
Louis Cypher
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
 
Louis Cypher
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic