Problem with moving JSPs under WEB-INF directory

泄露秘密 提交于 2019-12-08 04:29:59

问题


I am facing a problem when I move my JSP files along with CSS and JS files under WEB-INF/web/ directory. The problem is that, when a JSP page loads, it does not load CSS and JS files. Please help if you have any idea about it.

Thanks

Umar


回答1:


Unless you want to write controllers to serve the css/js files in the WEB-INF folder, you will need to move those files out of WEB-INF so that they can be served as static files by the app server.




回答2:


WEB-INF is not web accessible, you need to put css/js into public_html(www) as browser loads them through http.




回答3:


You can use the contextPath to retrieve any file from the foot folder,this way can work with files inside and outside WEB-INF folder.

You can make like this

<link rel="stylesheet" href="${pageContext.request.contextPath}/css/fromStyle.css" type="text/css">



回答4:


To access 'WEB-INF' use

getServletContext().getRealPath("/WEB-INF/...");


来源:https://stackoverflow.com/questions/1365867/problem-with-moving-jsps-under-web-inf-directory

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