2011-07-09 47 views
0

可能重複:
JSP can't find stylesheetJSP找不到樣式表,圖片

Tomcat7,春天框架3,JSTL 1.2。 層次結構:WEB-INF/jsp WEB-INF /樣式

我在我的JSP文件中鏈接樣式表,它位於WEB-INF/jsp中:但它不起作用!當我打開我的應用程序是沒有風格,並writter被Tomcat:

 
Apache Tomcat/7.0.14 - Error report 
HTTP Status 404 - 

type Status report 

message 

description The requested resource() is not available. 
Apache Tomcat/7.0.14 

所以我把我的文件夾的樣式進行WEB-INF的,它仍然無法正常工作! 此外,圖像也無法正常工作,但我的圖像文件夾不在WEB-INF中,它們的路徑是corect ... 問題是什麼?

+4

你已經問了同樣的問題,準確,並得到了迴應:你不能把CSS文件的WEB-INF。如果您需要更多幫助,請編輯原始問題,向我們展示您的JSP代碼,並告訴我們所有相關文件在目錄樹中的位置。 –

回答

3

在春天我把我的資源放在web-inf之外的文件夾中。就像這樣:

enter image description here

的web.xml

<!-- 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中(在web.xml中指定配置文件)文件我排除在被管理的資源目錄調度程序,因此調度程序不會收到帶資源前綴的URL,並嘗試將其路由到適當的控制器。

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

在我的jsp然後我就可以訪問資源正常:

<link rel="stylesheet" type="text/css" href="/skillsmanager-ui/resources/css/reset.css" /> 
+0

@Lomer很高興你得到它的工作感謝接受。當我第一次設置它時,我也遇到了問題。請記住,您的調度員將會收到您的所有請求並嘗試路由它們,除非您有規則設置來阻止它 –