无法在 JSP 中包含 WEB-INF 目录中的 javascript 文件。

发布于 2024-12-19 22:03:27 字数 262 浏览 6 评论 0原文

如何使用tomcat在jsp中包含以下文件夹WEB-INF\includes\header.js中的文件。我已在 jsp 文件中包含以下内容,但它不起作用“

<script type="text/javascript" src="WEB-INF/includes/header.js"></script>

”。它没有获取 header.js,当我查看源代码并尝试单击 src 链接时,它显示资源未找到 404 错误。

How to include a file in the following folder WEB-INF\includes\header.js in jsp using tomcat. I have the included the following in jsp file but it does not work "

<script type="text/javascript" src="WEB-INF/includes/header.js"></script>

". It is not getting the header.js and when i view source and try to click on the src link it says resource not found 404 error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

臻嫒无言 2024-12-26 22:03:27

像这样在 "WEB-INF" 之前放置一个 "/"

<script type="text/javascript" src='<c:url value="/WEB-INF/includes/header.js"/>'></script>

这样就可以正常工作了。 :)

Put a "/" before "WEB-INF" like this,

<script type="text/javascript" src='<c:url value="/WEB-INF/includes/header.js"/>'></script>

and it will work fine. :)

慕烟庭风 2024-12-26 22:03:27
<script type="text/javascript">
<%@include file="../foo.js" %>
</script>

foo.js 位于 WEB-INF/jsp 下,包含它的文件位于 WEB-INF/jsp/common 下

<script type="text/javascript">
<%@include file="../foo.js" %>
</script>

foo.js is under WEB-INF/jsp and the file include it is under WEB-INF/jsp/common

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文