This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
I am to implement a requirement where in there are some html files placed on an FTP location. I have to create a web application, where a particular user will login and click a link. On click, the application should get the Home HTML from the FTP location and display in the browser. In the Home HTML again there are links to other HTML's on that FTP folder.
I tried using the using anchor tag in JSP, but that doesn't work. Can anyone suggest how to achieve this functionality?
That means the URL isn't correct. What have you done to debug this?
tarunbhatia bhatia
Greenhorn
Joined: Mar 09, 2011
Posts: 5
posted
0
[M Mehta]
Basically problem is Home HTML has internal links to other htmls. These html are lying on the ftp location (not on the web application) server. And the Home HTML has relative path given to these htmls.
Thus when you click on any hyperlink of Home HTML, it tries to locate the html on the ROOT node of web application.
Expectation:
-------------------------------------------------------------
- How to ensure it tries to pull the next html from ftp location.
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 1002
posted
1
Let me get this straight
In effect what you are after is a proxy to an ftp site, so that the html files there can be served as if the ftp site was an http server.
Sounds convoluted to me... A huge overhead for what gain?
So you need a servlet which can connect to this ftp site, download the resource you want from it, and then send that resource out in the Response.
This servlet will also need to be invoked on links from this downloaded page.
One servlet can be configured to handle all the requests. I would approach it in this fashion:
Configure a servlet filter to dispatch all requests going to /ftp/* to the "ftp servlet", and then use the remaining part of the request to determine what resource to download from the ftp site.
e.g. accessing /myWebapp/ftp/pageFromFTPSite.html would invoke the "ftp" servlet, and load "pageFromFTPSite.html"
Depending on the html pages deployed on the ftp site that may or may not be enough.
If the html pages use relative links ie that should work perfectly well.
Thanks Stefan. I got your point. I would be able to write a servlet to connect to ftp and download the html from there.
However if you could help me with modifying the response received from ftp and show it on my jsp so that hyperlinks are fashioned in a way that it invokes the servlet again.
Your help will be really appriciable and i'm thankful to you.
Following are the links on my home page, these html are also placed in the same folder of my home page html.
These links match the servlet filter ("/ftp/*") and would thus invoke the ftp servlet.
By examining the request URL you should be able to pull out the resource to download from the FTP site.
If all the links are like this, you should have no issues :-)
cheers,
evnafets
tarunbhatia bhatia
Greenhorn
Joined: Mar 09, 2011
Posts: 5
posted
0
Thanks Stefan. I'll build the application based on the pointers provided. Thanks for your help.
tarunbhatia bhatia
Greenhorn
Joined: Mar 09, 2011
Posts: 5
posted
0
Hi Stefan,
Thanks for your help. My pages are coming up properly, each hyperlink working fine. But I'm left with one problem.
My pages have image tags too and these images are also lying on ftp server. And clue that i have got is you cannot return content type as HTML and Image in one response from servlet. So my assumption is I need to write another servlet that is invoked when html page is rendered on browser.
I'd do the following:
1. Return the html page from servlet1.
2. Content returned by servlet1 will have image tags like <img src="xdoimgFv.png">
3. When html page is being rendered on encountering img tag, servlet 2 will be invoked.
4. Servlet 2 will download the image from ftp and return the response object as image.
Is this thought correct?
Any pointers or source code will be really helpful. I'm new to servlet programming thus any sort of information will help.