Can not include javascript file from WEB-INF directory in JSP.

拈花ヽ惹草 提交于 2019-12-31 04:13:55

问题


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.


回答1:


<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




回答2:


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. :)



来源:https://stackoverflow.com/questions/8391467/can-not-include-javascript-file-from-web-inf-directory-in-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!