• Post Reply Bookmark Topic Watch Topic
  • New Topic

how we can post to another url from servlet ?  RSS feed

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post
is it possible that we post to another url from a servlet ?
I tried to use response.sendRedirect(URL_AND_DYNAMICLY_MADE_PARAMS) but the 3rd party url said that its servlet does not support GET method.
so , is there any way to post to another URL from servlet instead of sendig the param using get method ?



thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HttpClient toolkit in the Apache Commons project has a convenient way to create a POST and generally emulate a browser. Probably easier than writing your own based on HttpURLConnection - however, note that the reply will come back to your servlet so this is NOT like sendredirect.

If you want the effect of redirecting the user and creating a POST write a page with hidden form variables and Javascript to POST the form as soon as the page loads.

Bill
 
Durgaprasad
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thing is you cannot post.
The easier way is to set a hidden variable before forwarding.

In the forwarded page's doget method check for that variable value. If it is set then call the dpPost method.

May be a silly answer but definetly not a stupid one


SCJP 91
SCWCD perparing
ISDX perparing
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Durgaprasad,
Welcome to JavaRanch!

We're pleased to have you here with us in the servlets forum, but there
are a few rules that need to be followed, and one is that proper names are
required. Please take a look at the
JavaRanch Naming Policy and
adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use URLConnection for posting to another servlet.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!