简体   繁体   English

生成的java tomcat链接不起作用

[英]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. 我只是在做一个java tomcat项目,它在数据库中进行一些查询然后返回一些网页的文件路径。

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. 现在我已经在web.xml中映射了我唯一的类,并且webapp确实返回了一个url列表,这些url对应于我本地磁盘中的一些html页面。 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. 我在webapp中设置了一个侧框架,我的想法是我在输出页面输出结果,如“file:/// file_path_of_html_page”,当点击此链接时,侧框将显示html页面。

But actually I got the right links but when I click on them, nothing happens, chrome tells me "Not allowed to load local resource". 但实际上我得到了正确的链接但是当我点击它们时,没有任何反应,chrome告诉我“不允许加载本地资源”。 Even I set the target="_blank", the link doesn't work. 即使我设置target =“_ blank”,链接也不起作用。 But the "file:///filepath" are all ok when I type them in the address bar. 但是当我在地址栏中输入它们时,“file:/// filepath”都可以。 I've moved all the html pages in the eclipse project folder but that didn't help. 我已经移动了eclipse项目文件夹中的所有html页面,但这没有帮助。

Any suggestions to do this simple task? 有什么建议去做这个简单的任务吗?

The average browser disallows due to security reasons opening file:// resources when the parent resource is by itself served over http:// . 由于安全原因,当父资源本身通过http://提供服务时,平均浏览器不允许打开file://资源。 If you make them fullworthy http:// links, then it will work properly. 如果你使它们具有完整的http://链接,那么它将正常工作。

Even if the browser allowed it, this approach would not going to work when you publish the webapp on a different server. 即使浏览器允许,当您在不同的服务器上发布webapp时,这种方法也不会起作用。 A file:// resource refers to the local disk file system, which is the one the client (the user with the webbrowser) is using. file:// resource指的是本地磁盘文件系统,即客户端(具有webbrowser的用户)正在使用的系统。 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. 客户端应事先在其自己的本地磁盘文件系统上拥有完全相同资源的副本,以便使file://链接起作用。

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. 只需将HTML页面放在Web项目的公共Web根目录中(通常放置JSP文件的位置等),然后使用(相对) http://链接来引用HTML页面。 For example, the following link in a http://localhost:8080/contextname/some.jsp 例如, 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. 将打开http:// localhost:8080 / contextname / some.html文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM