Scott Evans wrote:
>
> In Servlet A's doPost, you can call doGet (still Servlet A) and then forward
> to Servlet B.

No, I'm afraid that doesn't solve the problem. There's no way you can
change the request's method since, even when you forward it to another
servlet (or JSP page), it still represents the request sent by the
browser. The original servlet and the target servlet are both processing
the *same* request. Changing the method when going from one to the other
would be like changing history; the request was sent as a POST request
so you can't just go back and change it to GET. Changing the method
could also mean loosing all parameters, since a POST request carries them
in the message body while a GET carries them in the query string.

If the target servlet needs to process a POST request, it should implement
the doPost() method. I'm not sure why that seems to be a problem in this
case. There's nothing wrong with a servlet that does the same processing
for GET and POST, e.g. by letting doGet() just call doPost() or vice versa.

If, for some reason, the target servlet must only deal with GET requests,
the first servlet can redirect to it instead of using forward. A redirect
of a POST request is (typically) processed by the browser as a GET request
to the new URL. Note, though, that all POST request parameters are lost with
this approach, unless you read them from the POST request and add them as a
query string in the URL used for the redirect.

Hans
> > -----Original Message-----
> > From: Serbulent Ozturk [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, May 18, 2000 5:03 PM
> > To: [EMAIL PROTECTED]
> > Subject: doPost() to doGet() via RequestDispatcher
> >
> >
> > Hi,
> >
> > My Servlet-(A) gets a POST request from a form after
> > processing it I need to
> > pass it to another Servlet-(B) but I need to pass it to
> > Servlet(B)'s doGet()
> > method.  As the original request line was POST, it always invokes
> > Servlet-(B)'s doPost().
> >
> > <PRE>
> > getServletContext().getRequestDispatcher("/servlet/B").include
> > (req, res);
> > <PRE>
> >
> >
> > I guest I can set an attribute in the request in the
> > Servlet-(A) before
> > dispatching and retrieve it at the begginning of Servlet-(B)
> > doPost() and if
> > true call the doGet(), as a work around.
> >
> > However, although I could not fond t in API Socumentation, I
> > think there
> > must/should be a convential way of changing the Method type in the
> > Request-Line dynamically, as it is encapsulated as an object, i.e.
> > HttpServletRequest.
> >
> > Any ideas?
> >
> >
> > Bulent

--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to