File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Proxy Servlet Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Proxy Servlet Example" Watch "Proxy Servlet Example" New topic

Proxy Servlet Example

marc miller

Joined: Sep 12, 2003
Posts: 1
Hello out there,
my wish is to program a servlet, that takes the URL from a Request-Parameter,, then retrieves the content of the given URL and finally outputs the content to the client...
Has anyone a simple example for me?
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

This is a very short and very contrived example, but it goes like this:
The User selects a display page from a list. The name of this display page is passed to a Servlet as a parameter. The servlet will then return the page to the client. Just to make it interesting, the Servlet also assumes that it has to prepend a directory to the JSP that the user does not know about.
I'd also like to point out that passing file names like this is a security risk since the user can write any filename into the URL. It's not a good idea to clients this sort of control.
The servlet will be mapped as /MyServlet and look like this:

and you call it like this: /MyServlet?filename=myfile.jsp or /MyServlet?filename=myfile.html
Hope this helps. It's a bit of a short example, but might get you started.
I agree. Here's the link:
subject: Proxy Servlet Example
It's not a secret anymore!