aspose file tools*
The moose likes JSP and the fly likes display FTP content Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "display FTP content" Watch "display FTP content" New topic
Author

display FTP content

M Mehta
Ranch Hand

Joined: Aug 03, 2006
Posts: 92
Hi,

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?

Thanks,
Me
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Me Mehta wrote:I tried using the using anchor tag in JSP, but that doesn't work.

Please explain what "doesn't work" means. I assume it means that your keyboard burst into flame?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
M Mehta
Ranch Hand

Joined: Aug 03, 2006
Posts: 92
It gives a 404 error when I click on the link created by anchor tag.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

That means the URL isn't correct. What have you done to debug this?
tarunbhatia bhatia
Greenhorn

Joined: Mar 09, 2011
Posts: 5
[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: 1018
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.

If they use absolute links in some fashion eg
it would get complicated.
Your servlet would have to modify the html on the way through to generate hyperlinks that would direct back through the ftp servlet again.
Possible, but even more overhead again.

those are my thoughts anyway.
cheers,
Stefan
tarunbhatia bhatia
Greenhorn

Joined: Mar 09, 2011
Posts: 5
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.

[tr class="c3"][td valign="middle" class="c10"] [a href=".\RDD_2300_D02_P01.html"] Inspector Feedback[/a][/td][/tr]
[tr class="c3"][td valign="middle" class="c10"][a href=".\RDD\RDD_2300_D03_P01.html"] Latest Outcome[/a][/td][/tr]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Those are relative links. As such they should "just work" if you followed the process outlined in my post earlier.

A relative link means it will use the "current url" as a base, and then tack the changes on to the end.

So if your original response was http://myserver/mywebapp/ftp/index.html
These links would effectively be

http://myserver/mywebapp/ftp/RDD_2300_D02_P01.html
and
http://myserver/mywebapp/ftp/RDD/RDD_2300_D03_P01.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
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
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.

Thanks,
Tarun
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42294
    
  64
That's the correct approach.


Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: display FTP content