JSP can't find stylesheet

前端 未结 3 502
北恋
北恋 2021-01-24 11:17

Hierarchy:
WEB-INF/jsp
WEB-INF/styles

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

 

        
相关标签:
3条回答
  • 2021-01-24 11:22

    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.

    0 讨论(0)
  • 2021-01-24 11:29

    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.

    0 讨论(0)
  • 2021-01-24 11:41

    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 讨论(0)
提交回复
热议问题