JS/ CSS files not found due to path differences java, spring mvc, velocity

二次信任 提交于 2019-12-06 19:34:26

thats because the resources you have declared are relative to the url used for accessing the view. You have to change all the static resource urls to absolute You can do this using tag

change from this

<script src="resources/custom.js"></script>

to

<script src="<c:url value="/resources/custom.js"/>"></script>

this should generate something like this in the HTML

<script src="<c:url value="http://www.example.com:8080/FolderA/resources/custom.js"/>">
</script>

Note But for this to work you should add %@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> to your jsp and include jst tag library into the webapp

Edit------

For the paths referred inside in JS and CSS files , there is a work around.Use base tag to define the absolute path tags in the HTML need to use

<base href="http://www.example.com:8080/FolderA/">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!