Servlet redirection & POST method

I need to redirect one servlet I have, to another servlet situated in other machine using post method. Is it possible?

LucsatAsked:
Who is Participating?
 
heyhey_Commented:
http://www.javaworld.com/javaworld/javatips/jw-javatip34.html

Java Tip 34: POSTing via Java

another time ?
0
 
WilliamCHallCommented:
You can use the method:

public void sendRedirect(java.lang.String location)
                  throws java.io.IOException

     Sends a temporary redirect response to the client using the specified redirect location URL.
     This method can accept relative URLs; the servlet container will       convert the relative URL to an absolute URL before sending the response to the client.


This will not however allow you to retrieve any variables from your first servlet in the second.  If you want to do that, you'd need to redirect to a jsp first and then to a servlet on another machine.  You can use this code in your servlet to redirect to a jsp.

req.setAttribute("items", item_vector);
getServletContext().getRequestDispatcher("/store/CheckOutJSPCart.jsp").forward(request, response);

In the local jsp file, you'll now be able to get to the variable items which contains item_vector from the servlet.
0
 
rjackmanCommented:
hi Lucsat

try these links:

http://webreview.com/pub/97/11/28/webdev/

http://www.servertec.com/products/iws/samples/servletchaining_src.html

http://java.sun.com/docs/books/tutorial/servlets/communication/other-servlets.html

but if u have to use the methods of the servlets those r situated on other servers then u have to use the RMI
but if u have to invoke other servlet then u can do it in post method by just
http://url request(url request -->IP address of the server/dir where servlet is stored/name of the servlet)

BestLuck
Rjackman
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
heyhey_Commented:
just send normal HTTP POST request.
0
 
LucsatAuthor Commented:
heyhey... Read my question another time...
0
 
LucsatAuthor Commented:
Thank you for your help, heyhey. I don't know if finally I will use this method, or a pack of cookies, but it's very interesting...
0
 
heyhey_Commented:
thanks for the points :)
0
 
LucsatAuthor Commented:
you're wellcome... ;)))))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.