• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

servlet calling servlet

Hi.
I havea  JSP which will call a servlet which will do all the procesing and then depending on the outcome of the result will transfer the results to another servlet. Thats my requirement.

I am using
rd = getServletContext().getRequestDispatcher("/<servlet>");
rd.forward(request, response);

But the outcome is, the other servlet is called but the URL contains the request value in post method and still contains the caller servlet name on it. So if someone refreshes the page, the caller servlet is called which does the same procesing again.

Is there a way to completely transfer the control to the called servlet?
0
PraKash
Asked:
PraKash
  • 3
  • 3
2 Solutions
 
aozarovCommented:
You can use the httpservletresponse sendRedirect instead.
0
 
bloodredsunCommented:
as aozarov says, you can use response.serndRedirect("myPage.do") but be aware that this method makes the browser send a completely new request to the url specified which means that you will lose any data stored in the request scope.

>>But the outcome is, the other servlet is called but the URL contains the request value in post method and still contains the caller servlet name on it. So if someone refreshes the page, the caller servlet is called which does the same procesing again.

I would store a variable in the request that would prevent repeat submissions rahter then use sendRedirect() if you have information stored in the request.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
aozarovCommented:
> means that you will lose any data stored in the request scope.
I think there is a way to append it (in case of GET request) via response.serndRedirect("/servlet?" + getQueryString()), no?
But I agree that this is not the aproach that should be taken to prevent double sumit (it is need if it is important for the browser to know the direct page e.g. bookmarks)
0
 
bloodredsunCommented:
>>I think there is a way to append it (in case of GET request) via response.serndRedirect("/servlet?" + getQueryString()), no?

Yep, in fact thats a great way. But you can only use it for GET request and request parameters, anything stored in the request object via request.setAttribute(String, Obj) will be lost.
0
 
PraKashAuthor Commented:
actually,

I refrained from using redirect because it used to give me the error saying maximum redirect reached. Cannot redirect(in firefox).

I dont understand what error was so I stopped using that. Now used it again and am not getting that error. in any browser. If I am able to reproduce that error, I will let you know.

And bloodredsun, redict give an all new URL and you are right and does not show the previous servlet so when I refresh that does not happen. And you are right. the request variables are lost. But I think I will use the session to store those variables.
0
 
bloodredsunCommented:
yes, if you store your info in the session, you can use this quite happily.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now