开发者

JSP can't find stylesheet

开发者_StackOverflow社区Hierarchy:

WEB-INF/jsp

WEB-INF/styles

I link stylesheet in my JSP file, which is located in WEB-INF/jsp:

 <link rel="stylesheet" type="text/css" href="../styles/reset.css" />

But it doesn't work! When i open my application there is no styles, and writter by 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>

How can I overcome it?

My project: http://img835.imageshack.us/img835/6159/73536381.jpg

I am using spring framework 3. I've put my folders with styles and images outside of WEB-INF but it still doesn't work. I my jsp file is written:

<link rel="stylesheet" type="text/css" href="resources/styles/styles.css" />

And it doesn't work...


I've found http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-static-resources So now my rus-servlet.xml looks like this:

<?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>

But this in JSP still doesn't work!

<link rel="stylesheet" type="text/css" href="resources/styles/styles.css" />

And i have 3.0.5 version of my spring framework.


All the files stored in WEB-INF are, on purpose, invisible to the outside. A URL pointing on WEB-INF/something will thus always result in a 404. WEB-INF is used to store resources needed by the application, but which must stay invisible to the outside.

Put the CSS files outside of 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". Since you have your JSPs in WEB-INF/jsp I assume you are using JSF or some other facading framework?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜