aspose file tools*
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
Author

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.

Thanks,
Sai


SCJP 5.0, SCWCD 5, preparing for SCDJWS
Ben Souther
Sheriff

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: http://aspose.com/file-tools
 
subject: changing http get request to post request
 
Similar Threads
How to make a 'post' request from an application to a Servlet
Call servlet from action class
Since ServletContext's getServlet(...) is deprecated, how do i get a servlet?
Q 14 page 61 Authore Charles lyons
How do I retrieve Javascript values from a Java servlet?