繁体   English   中英

JSP 找不到样式表

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM