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

changing http get request to post request

Venkata Kumar
Ranch Hand

Joined: Apr 16, 2008
Posts: 110

Hi All,

I am facing this problem in my application. I have two servlets, servlet A and servlet B. Servlet A receives a GET request , process the request and forwards it to servlet B. Servlet B handles POST requests only. I shouldn't change the code of Servlet B.
Is it possible to change the request type from GET to POST in servlet A or Is there any way to create a new POST request from servlet A to servlet B.
Any information on this is really useful.


SCJP 5.0, SCWCD 5, preparing for SCDJWS
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

The method property of HttpServletRequest is read only.

Adding a doGet method to servlet B would be the easiest thing to do but if that's not possible, you could wrap the request, providing your own getMethod method. The servlet spec provides the HttpServletRequestWrapper to take some of the grunt work out of this.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ashok Kumar Babu
Ranch Hand

Joined: Jul 25, 2006
Posts: 129
Hi Ben,

I was looking for solution for a similar scenario. Thanks for your post.

Your idea works pretty good.

Ashok<br /> <br />SCJP 91%<br />SCWCD 88%
I agree. Here's the link:
subject: changing http get request to post request
It's not a secret anymore!