[英]JSP can't find stylesheet
等級制度:
WEB-INF/jsp
WEB-INF/樣式
我在位於 WEB-INF/jsp 中的 JSP 文件中鏈接樣式表:
<link rel="stylesheet" type="text/css" href="../styles/reset.css" />
但它不起作用,當我打開我的應用程序時,沒有 styles: 和 Tomcat 的作者:
<html><head><title>Apache Tomcat/7.0.14 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The requested resource () is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.14</h3></body></html>
我怎樣才能克服它?
我的項目: http://img835.imageshack.us/img835/6159/73536381.jpg
我正在使用 spring 框架 3。我已經將我的文件夾與 styles 和圖像放在 WEB-INF 之外,但它仍然不起作用。 我的 jsp 文件是這樣寫的:
<link rel="stylesheet" type="text/css" href="resources/styles/styles.css" />
而且它不起作用...
我找到了 http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resources所以現在我的 rus-servlet.xml 看起來像這樣:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="rus.web"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/"/>
</beans>
但這在 JSP 中仍然不起作用!
<link rel="stylesheet" type="text/css" href="resources/styles/styles.css" />
我有我的 spring 框架的 3.0.5 版本。
存儲在 WEB-INF 中的所有文件都故意對外不可見。 指向 WEB-INF/something 的 URL 將始終導致 404。WEB-INF 用於存儲應用程序所需的資源,但必須保持對外部不可見。
將 CSS 文件放在 WEB-INF 之外。
By default Tomcat will not serve static files from WEB-INF/, move your css up a level so the css is "./styles/some.css". 由於您在 WEB-INF/jsp 中有您的 JSP,我假設您正在使用 JSF 或其他一些外觀框架?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.