Hi,

Use this method to direct your requests (not responses :-) ).

ServletContext ctx = getServletConfig().getServletContext();
RequestDispatcher disp = ctx.getNamedDispatcher("secondServlet");
disp.forward(req, resp);

furthermore,
you can create a utlity class with method goToServlet and just pass it the
required attributes and let it do the job.

What this method does is forwards the request so that another servlet can
take a look at it before sending it to the client. The request method is
kept the same (i.e. it is Get if the servlet calling it has been called thru
Get and Post if otherwise).

Imp:
a. Do not let the first servlet set the content type or get the output
stream.
b. The getNamedDispatcher is method of Servlet 2.2 API. Use the
getRequestDispatcher for 2.1 but I could get it to work only for forwarding
to JSPs not to servlets.

I hope it answers your question.

Thanks,
tanmay




-----Original Message-----
From: Arnaud D [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 24, 2000 3:34 PM
To: [EMAIL PROTECTED]
Subject: sendRedirect to doPost


Good evening people,

How can I redirect from servlet A to servlet B, but in servlet B I want the
doPost() method to be called not the doGet.
Unfortunatly the response.sendRedirect("/servlet/servletB"); will call the
doGet method...
I have the same problem with frames. If servlet A is in the bottom frame,
how can it sendRedirect to the top frame ???

My workaround is to create a servlet that has the doGet method like the
doPost method of servlet A, and to stop using frames (wich is good IMO), but
I want to make sure that i'm not missing out on something clever.

Thank you for your time.

Arnaud "go to bed now" Dostes

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to