Tomcat7、Spring Framework3、jSTL 1.2。 层次结构:WEB-INF/jsp WEB-INF/stylesPossible Duplicate:
JSP can't find stylesheet
我在 JSP 文件中链接样式表,该文件位于 WEB-INF/jsp 中:但它不起作用!当我打开我的应用程序时,没有样式,并且由 Tomcat 编写:
Apache Tomcat/7.0.14 - Error report HTTP Status 404 - type Status report message description The requested resource () is not available. Apache Tomcat/7.0.14
所以我将样式文件夹从 WEB-INF 中取出,但它仍然不起作用! 另外,图像也不起作用,但我的图像文件夹不在 WEB-INF 中,并且它们的路径是正确的... 有什么问题吗?
最佳答案
在 Spring 中,我将资源放在 web-inf 之外的文件夹中。像这样:
Web.xml
<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
然后在我的 servlet-context.xml(web.xml 中指定的配置文件)文件中,我将资源目录排除在调度程序管理之外,因此以 resources/为前缀的 URL 不会被调度程序拾取并尝试路由到适当的 Controller 。
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
在我的 jsp 中,我可以正常访问资源:
<link rel="stylesheet" type="text/css" href="/skillsmanager-ui/resources/css/reset.css" />
关于java - JSP找不到样式表、图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6633789/