darkjh
darkjh

Reputation: 2861

java tomcat links generated don't work

I'm just doing a java tomcat project, that does some query in a database then return the file path of some web pages.

Now I have mapped my only class in web.xml and the webapp does return a list of urls which correspond to some html pages in my local disk. I set up a side frame in the webapp, my idea is that I output the results in the output page like "file:///file_path_of_html_page" and when this link is clicked, the side frame will show the html page.

But actually I got the right links but when I click on them, nothing happens, chrome tells me "Not allowed to load local resource". Even I set the target="_blank", the link doesn't work. But the "file:///filepath" are all ok when I type them in the address bar. I've moved all the html pages in the eclipse project folder but that didn't help.

Any suggestions to do this simple task?

Upvotes: 1

Views: 507

Answers (1)

BalusC
BalusC

Reputation: 1108742

The average browser disallows due to security reasons opening file:// resources when the parent resource is by itself served over http://. If you make them fullworthy http:// links, then it will work properly.

Even if the browser allowed it, this approach would not going to work when you publish the webapp on a different server. A file:// resource refers to the local disk file system, which is the one the client (the user with the webbrowser) is using. This is normally in a physically different machine. The client should have a copy of exactly those resources on its own local disk file system beforehand in order to get the file:// links to work.

Just put the HTML pages in public web root of your web project (there where you normally put your JSP files and so on) and use (relative) http:// links to refer the HTML pages. For example, the following link in a http://localhost:8080/contextname/some.jsp

<a href="some.html">link to some html file</a>

would open the http://localhost:8080/contextname/some.html file.

Upvotes: 4

Related Questions