我在jsp-servlet中遇到问题,当我将index.jsp设置为welcome-file(项目运行时,首先运行的默认页面),那时CSS和JS文件不是渲染。 我的项目Hierarchy就像这样
-ProjectName
- 用户
-css
-js
-index.jsp
当我运行我的项目时,浏览器中的URL将是localhost:8080/ProjectName
所以这里调用了index.jsp但没有CSS和JS文件。
编辑:最后,我通过将CSS和JS复制到根目录也解决了这个问题。即我有CSS和JS @“User”以及“ProjectName”。
答案 0 :(得分:0)
尝试使用上下文路径
<link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css">
将为您提供css
文件夹中css文件的路径。或使用scriptlet
,
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/style.css">
但是,建议您不要在jsp中使用scriptlets
。