0

私のプロジェクトフォルダディレクトリは次のとおりです

SpringMVCTest/WebContent/WebInf/jsp/index.jsp

cssファイルは下にあります

SpringMVCTest/WebContent/style/main.css

私の問題は、index.jspからcssファイルにアクセスできないことです。試しました

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

と他の人も。

任意の提案をお願いします。

4

1 に答える 1

1

以下を servlet-context.xml ファイルに追加しましたか
編集
このファイルが Web.xml ファイルで読み取られている場所を見つけることができます: 少なくともこれは私のプロジェクトが使用する Spring Mvc 3.1 の場所です。 .

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

servlet-context.xml ファイル:

<!-- Handles HTTP GET requests for /WebContent/** by efficiently serving up static resources in the ${webappRoot}/WebContent directory -->
<resources mapping="/WebContent/**" location="/WebContent/" />

次に、jsp から次のものを使用できるはずです。

<link rel="stylesheet" type="text/css" href="/WebContent/style/main.css">

上記は、Spring に DispatcherServlet を介してこれらの静的アセットを処理しないように指示します

于 2012-12-31T10:24:18.333 に答える