找不到外部CSS文件

时间:2011-11-02 11:14:37

标签: css jsp

http://i.stack.imgur.com/fAgnx.pngv(我编辑了帖子,所以必须换回网址链接,抱歉)。

上面是我在Eclipse中的目录布局。我的master.jsp(在/view/layouts/master.jsp中找不到带有此路径的css文件:

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

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

调度-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:annotation-config />
    <context:component-scan base-package="controller" />

    <mvc:annotation-driven />

    <mvc:interceptors>
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    </mvc:interceptors>

    <mvc:view-controller path="/" view-name="index" />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

的web.xml

<?xml version="1.0" encoding="utf-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>sitemesh</filter-name>
        <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>sitemesh</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>REQUEST</dispatcher>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>dispatcher</welcome-file>
    </welcome-file-list>
</web-app>

2 个答案:

答案 0 :(得分:1)

您需要将上下文路径插入到您的webapp(例如/test-app/css/styles.css)或使用相对路径。相对路径与Eclipse目录结构无关,而是与您的HTTP请求相关。例如如果您要求:

/测试应用程式内/ MyServlet

然后你的CSS的相对路径是

CSS / styles.css的

答案 1 :(得分:0)

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