• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

display FTP content

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
M Mehta
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It gives a 404 error when I click on the link created by anchor tag.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That means the URL isn't correct. What have you done to debug this?
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[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.
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
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
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stefan. I'll build the application based on the pointers provided. Thanks for your help.
 
tarunbhatia bhatia
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the correct approach.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic