[英]Absolute path in a web app
This may sound like a dumb question. 这听起来像是一个愚蠢的问题。
I received a (basic) web application developed by another person, using HTML and JavaScript . 我收到了另一个人使用HTML和JavaScript开发的(基本)Web应用程序。 In this application he used his JavaScript file path as
/javascripts/_FileName_.js
. 在此应用程序中,他使用了JavaScript文件路径作为
/javascripts/_FileName_.js
。 But when I tried to run it on a Tomcat (8.5) server, those JavaScript files didn't executed. 但是,当我尝试在Tomcat(8.5)服务器上运行它时,那些JavaScript文件没有执行。 But when I changed the path to
javascripts/_FileName_.js
(Without the /
at the beginning), it worked fine. 但是,当我将路径更改为
javascripts/_FileName_.js
(开头没有/
),它可以正常工作。
This application was already ran in a server and it worked fine. 该应用程序已经在服务器中运行,并且可以正常工作。 What has to be the problem here ?
这里有什么问题?
as @duffymo described in comments, the leading slash tells tomcat to start looking for that file at the root of the application context, which is the webapps
folder in tomcat. 如@duffymo在评论中所述, 前导斜线告诉tomcat开始在应用程序上下文的根目录(即tomcat中的
webapps
文件夹)中查找该文件。 But if we remove that leading slash , it searches for the file from the current folder. 但是,如果我们删除该前导斜线 ,它将从当前文件夹中搜索文件。
That was the problem. 那就是问题所在。 I am posting this as an answer because he mentioned these in comments only.
我将其发布为答案,因为他仅在评论中提到了这些。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.