Forums Register Login

sendRedirect as POST

+Pie Number of slices to send: Send
Hello Code Ranch,

I have a question on redirecting to a servlet. I have noticed that sendRedirect() method would always end up in the doGet method of the redirected page. how do I make sendRedirect point to doPost of the redirected page.

Page1Servlet


Page2Servlet


I have heard of some work around like creating a jsp or html form that would forward the parameter. But is there a way to do this in servlets.

Thanks,
Ian
+Pie Number of slices to send: Send
Generally, you cannot send a POST request using sendRedirect method. Why do you need doing that?
Moving to Servlets forum.
+Pie Number of slices to send: Send
there is no direct way of sending a post request as the default method of request is get.also you cannot use response.sendredirect to send a post request.html form can be a solution to the problem.
+Pie Number of slices to send: Send
Thank you Devaka and Archit.

Yeah, sendRedirect is really HTTP-GET. I still havent found another way to redirect to another page/servlet.

@Deveka: I need to do this because I want to pass a volume of parameters to the target(page to redirect) page. And making another jsp/html form would mean I have to touch JSP(View) side. I was thinking of handling everything in the Servlet(controller) side of the system. But if you have something in mind, I'd gladly like to hear from you.

Ian
+Pie Number of slices to send: Send
It sounds as if both pages are part of the same web app, so why does it need to be a redirect? A server-side forward (using a RequestDispatcher) should work as well, and will also be faster.
+Pie Number of slices to send: Send
@Lester Burnham
even, i agree with your point.

@Ian
if you want to use post over get just to hide your parameter name and value then request dispatcher is the best option for you as it uses get but does not allow the url to be seen in the browser. but if you have something else in your mind then you have to opt for jsp/html form.
+Pie Number of slices to send: Send

Is it possible for us to send a POST request using a link (<a href="#">Sent Post Request</a>) ?

Thanks,

Rahul
+Pie Number of slices to send: Send
An HREF link will always use GET (unless it uses JavaScript to cause a form submit that uses POST).
+Pie Number of slices to send: Send
 

Lester Burnham wrote:An HREF link will always use GET (unless it uses JavaScript to cause a form submit that uses POST).



Yes, but then the form always uses POST method to submit, if we want to use the GET for some intention, then it will not be possible. Isn't it ?
+Pie Number of slices to send: Send
@rahul

Yes, but then the form always uses POST method to submit, if we want to use the GET for some intention, then it will not be possible. Isn't it ?


NO BUDDY,
form can use both <form action="" method="post"><input type="submit"></form> will send a post request and <form action="" method="get"><input type="submit"></form> will send a get request
+Pie Number of slices to send: Send
The underlying reason is that POST requests send paramters in the body of the request. Redirect can not recreate the body.

Getting the original POSTed parameters to the servlet at the new URL depends on where that destination is located - in the same application? In the same servlet container? In the same local network? ... etc.

Bill
+Pie Number of slices to send: Send
Hi,

It seems I have the exact same requirement
.... I want to POST data tp an external servlet but do NOT want to use html <form>. I want to use server side code (like redirect)

I am integrating my web application with multiple external service providers (all providing the same type of service)

With most of these extenal systems, integration is pretty simple, standard and same
---> build a URL with required parameters (as provided in the service providers documentation)
........and in the code, simply invoke response.sendRedirect(toConstructedURL);

Only one entity does it in a different way (why? I am )

... they have provided me a sample HTML.
........The HTML is nothing but a <form> with a action, with method 'post'and multiple hidden fields within.
.........when the form is submitted, integration is achieved.

and so I want an server side code alternative to an html form submit. (I do not want to build a adapter for this one single thing)


thanks
Jeevan
+Pie Number of slices to send: Send
You'll either need to do it yourself with the classes in java.net, or use a 3rd-party tool such as HttpClient, to send the request.

java.net.URLConnection
+Pie Number of slices to send: Send
i want to redirect to remote URL with some parameters in it's POST request....
Any idea???
+Pie Number of slices to send: Send
See the reply right above your own.
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 54492 times.
Similar Threads
going back
null pointer exception after response.sendRedirect() in jsp page.
Value shows up in url
How can i find out, from where my parameter coming from?
jsp page redirection
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 23:27:05.