Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I change a GET request to POST ?

 
Celina Paul
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you cannot. Why do you feel the need to do this?
bear
 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic