• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Forwarding from a servlet to a jsp.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Experts,
I have a jsp myjsp.jsp.
The jsp has a HTML form which submits/posts to a servlet.
The servlet processes the request and then forwards to the same jsp myjsp.jsp like so :
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/myjsp.jsp");
rd.forward(request, response);
My problem is when returning from the servlet I want the jsp to act as though it is receiving a completely new request.
Because there are parameters still in the request object when it gets forwarded myjsp.jsp is not behaving correctly.
Is there any way I can destroy the old request object once processed and force a new one. I am looking for behaviour similar to <jsp:forward ...>.
Please share solutions/workarounds.
Thank you.
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can code something like this on top of the jsp page to chk new request objects forwarded by ur servlet
<% if (request != null ) // To avoid execution on initialization of jsp
if (request.getParameter("YourParameter") != null) // u can use session that are initialized in servlet
{
//Perform some action
}

}
%>
 
Kel Walker
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does that mean that there is no way to generate a new request to the jsp from the servlet?
There are quite a lot of unwanted parameters in the request object that I would have to test for and ignore. This could make my jsp a bit messy.
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why not use sendRedirect() instead of forward() ?
sendredirect() acts exactly as you want (new request).
 
Kel Walker
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Roy Ben Ami,
That was the answer I was looking for. I knew there was a way.
Could you give me example syntax.
Thanks again.
 
Kel Walker
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No worries. I checked the javadocs.
Problem solved. Thank you.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You welcome
glad i could help
reply
    Bookmark Topic Watch Topic
  • New Topic