permaculture playing cards*
The moose likes Servlets and the fly likes How can I change a GET request to POST ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can I change a GET request to POST ?" Watch "How can I change a GET request to POST ?" New topic
Author

How can I change a GET request to POST ?

Celina Paul
Greenhorn

Joined: Nov 01, 2003
Posts: 16
The initial servlet gets a GET request.
It has to forward it to another servlet. Is it possible for the intial servlet to forward to the another servlet using a POST method ?
Amit KumarS
Ranch Hand

Joined: Oct 10, 2003
Posts: 100
hiiii Celina,

i donno if there is any way to do that.. but u can achieve this by doing one thing.. that is..
write both the methods (i.e. doGet and doPost) in your servlets and in doGet() you can call doPost like following.

i hope by this ur problem will be solved... do let me know if still in doubt.
Thanks
Amit


****************************<br />In 24 hrs Earth rotates once on its Axis.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

No, you cannot. Why do you feel the need to do this?
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Chandra Bairi
Ranch Hand

Joined: Sep 12, 2003
Posts: 152
You can directly forward the request to another servlet. The servlet to which you direct the request should contain the doPost method.it is as simple as this. kinldy let me know if there are any corrections.
good luck.


Thanks,
Shekar
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Note that a request has a method already, in the very first header. Simply forwarding a GET can't change it into a POST. RFC2616 lays out the rules for HTTP requests - a Yahoo search will find you a copy.
Your servlet could create a new POST request, send it, and then interpret the result to create a response, and there are other approaches. For example, you might be able to create a HttpServletRequestWrapper to be forwarded (but I have not tried this).
Bill
[ November 03, 2003: Message edited by: William Brogden ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I change a GET request to POST ?
 
Similar Threads
Ajax and servlet problem
forwarding request to some other server
Request Dispatcher calling mode
Forwarding requests between servlets
http method