gpt4 book ai didi

java - Spring 资源映射不适用于 localhost

转载 作者:行者123 更新时间:2023-11-30 08:13:33 25 4
gpt4 key购买 nike

设置

servlet-context.xml

<resources mapping="/resources/**" location="/resources/" />

.jsp

<script type="text/javascript" src="/resources/js/test.js"></script>

文件位置

webapp/resources/js/test.js

问题

当我访问localhost:8080/myApp/resources/js/test.js时找到了,但页面中实际呈现的内容是 localhost:8080/resources/js/test.js所以/myApp丢失了。

本地主机确实是这种情况还是我的设置有问题?

这是一个使用 STS(模板)制作的新 Spring MVC 项目,因此我怀疑它是设置,因为它从一开始就已经存在。

最佳答案

声明脚本时必须添加上下文路径

<script type="text/javascript" src="${pageContext.request.ContextPath}/resources/js/test.js"></script>

假设该脚本是在您的 jsp 页面中声明的。上下文路径指向应用程序的根目录。

关于java - Spring 资源映射不适用于 localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29997245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com