Instead of response.sendRedirect, use a URLConnection. That's not
exactly the same as having the browser repost, but it sounds like it
will accomplish what you're after. You can POST to a URL easily, like
this:
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
...
// Set up the connection.
URL url = new URL("http://mydomain.com/url_to_post_to");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// Encode the incoming parameters.
StringBuffer encodedParams = new StringBuffer();
Enumeration names = req.getParameterNames();
String sep = "";
while (names.hasMoreElements()) {
String name = (String)names.nextElement();
encodedParams.append(sep);
encodedParams.append(URLEncoder.encode(name));
encodedParams.append("=");
encodedParams.append(URLEncoder.encode(
req.getParameter(name)));
sep = "&";
}
// POST the request.
PrintWriter post = new PrintWriter(conn.getOutputStream());
post.print(encodedParams.toString());
post.flush();
post.close();
...
}
HTH,
Rod McChesney, Korobra
"Steven J. Owens" wrote:
>
> Somebody asked:
>
> > Is it possible to invoke the doPost() method (instead of the doGet()) of the
> > servlet to which I am redirecting using response.sendRedirect() ??
>
> No.
>
> As far as I've been able to find (and believe me, I've looked) it
> is not possible for the server to have the browser rePOST. If anybody
> has figured out how to do this, I'd appreciate a clue. A friend once
> explained the whys and hows of it to me in great detail, I'll append
> an excerpt from his message at the end of this post. So far, the only
> way I've found is to simulate it, having the servlet generate a page
> containing custom javascript.
>
> I suppose it could be done using a java applet, although the
> applet would be limited in which servers it could communicate with.
> Speaking of that limitation, what're the implications of having two
> different servers (different boxes, ip numbers, etc) with the same
> root domain? e.g. a user gets an applet from bar.foo.com, can the
> applet communicate with baz.foo.com? Or if the user gets an applet
> from just foo.com, can it communicate with baz.foo.com?
>
> Here're my friend's comments on the matter:
>
[snip]
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html