Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reverse Proxy Servlet 1

Status
Not open for further replies.

Sledgehammer777

Programmer
May 22, 2001
4
US
Has anyone seen or developed are servlet that will act as a reverse proxy? I need a servlet that will redirect to a different server and allow me to append parameters on the URL without the user knowing anything about the second server. How can this be done? I've been told I need a revrse proxy server to do this but because I need to dynamically modify the URL I pass along to the backend server I though about using a servlet. Any ideas?
 
RequestDispatcher should work fine if you are redirecting to an address relative to the servlet. If you must use an absolute address then you will have to use the sendRedirect method of the HttpServletResponse object. Here are some very sample examples of both.

Code:
/* Use RequestDispatcher from the HttpServletRequest */
String destination = "/newdestination.jsp?parm1=5";
RequestDispatcher rd = req.getRequestDispatcher(destination);
rd.forward(req, resp);

/* Use sendRedirect method of HttpServletResponse */
String destination = "[URL unfurl="true"]http://www.somewhere.com/newdestination.jsp?parm1=5";[/URL]
resp.sendRedirect(destination);
Wushutwist
 
I thought about these. I am sending to another physical machine so the RequestDispatcher will not work and I don't want to redirect via the client because I don't want them to know the URL of the backend server. Thank you but I think I still need an answer....
 
Then open a URLConnection and retrieve the page that you need. It may be a bit inefficient but that may be the only way.
Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top