File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes doPost() while using request dispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "doPost() while using request dispatcher" Watch "doPost() while using request dispatcher" New topic

doPost() while using request dispatcher

Suresh Khanna

Joined: Jan 04, 2004
Posts: 16
Hi guys,
Why can't we use doPost() when using request dispatcher.
I have two servlets where the first servlet is dispatching request to second servlet. The servlets are working fine when i am using doGet() method for both. When i tried to use doPost() method in both of them i am getting the following error.
HTTP Status 405 - HTTP method GET is not supported by this URL
type Status report
message HTTP method GET is not supported by this URL
description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

Apache Tomcat/4.1.27
Exaplation appreciated

Suresh k
Jacky Chow
Ranch Hand

Joined: Sep 01, 2002
Posts: 63
hi Suresh,
I guess that you typed the URL of the servlet in the browser directly, if this is your case, the problem is that the browser sends a HTTP GET request to you web server, and your servlet does not have a doGet method, so the servlet does not support the HTTP GET method!
Since the browser sends a request with HTTP GET method if you type the URL in the browser directly, the servlet that you type in the browser must implement the doGet method! But other servlets using request dispatcher to include/forward may implement the doPost method only!
[ January 28, 2004: Message edited by: Jacky Chow ]

I agree. Here's the link:
subject: doPost() while using request dispatcher
It's not a secret anymore!