我有一个 HTML 页面,它从用户那里获取用户名和密码并将其发送到 servlet。如果两者都正确,则 servlet 将分派(dispatch)到 JSP 页面。
RequestDispatcher rD = request.getRequestDispatcher("dynamic/faculty/updatefaculty.jsp");
rD.forward(request, response);
我分别检查了所有页面,它们都工作正常。 CSS文件 在 jsp 中加载,但是当我使用 dispatch 时,CSS 文件没有在 JSP 中加载。
当然,我从 NetBeans 中的 BrowserLog 收到了以下内容
Failed to load resource: the server responded with a status of 404 (Not Found) (04:11:01:478 | error, network)
at http://localhost:8080/css/forms.css
最佳答案
对于动态页面,您必须使用这种格式:
link href="${pageContext.request.contextPath}/css/sample.css"
静态响应没有值,使用下面的格式。这将盲目重定向。
response.sendRedirect("sample.jsp");
关于css - Request Dispatcher 不加载 jsp 中的样式表文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26598171/