2014-10-17 165 views
0

我做了映射圖像文件中,如下所示Spring上下文文件:靜態資源映射

<mvc:resources mapping="/images/**" location="/WEB-INF/images/" /> 

我測試這個在URL在瀏覽器地址欄中的圖像的直接訪問: hhttp://主機:port/ManageDepartments/images/oracle.PNG

它在瀏覽器上呈現請求的圖像,但爲什麼它阻止了用於請求服務的spring controller url。在春天的上下文文件中的圖像的url映射後,當我嘗試在url下面返回404錯誤。

http://host:port/ManageDepartments/department/ 

在上下文文件中執行映像映射後沒有獲取部門主頁!

對JSP,下面是spring配置文件中的配置:

<bean id="jspViewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" 
     p:suffix=".jsp" />  

下面是項目結構:

enter image description here

任何建議高度讚賞!

的web.xml

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

    <display-name>Spring With MongoDB Web Application</display-name> 

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

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> 
</context-param> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

</web-app> 

調度

<?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:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.2.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.2.xsd"> 

<context:component-scan base-package="com.rislg" /> 

<mvc:resources mapping="/images/**" location="/WEB-INF/images/" /> 

<!-- Factory bean that creates the Mongo instance --> 
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean"> 
    <property name="host" value="localhost" /> 
</bean> 

<!-- MongoTemplate for connecting and quering the documents in the database --> 
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"> 
    <constructor-arg name="mongo" ref="mongo" /> 
    <constructor-arg name="databaseName" value="test" /> 
</bean> 

<!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes --> 
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> 


<bean id="jspViewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" 
     p:suffix=".jsp" />  

</beans> 

在控制檯中,我不是在尋找任何錯誤,但在瀏覽器中我得到HTTP狀態404時,我打hhttp://主機:端口/ ManageDepartments/department /之前正在獲取部門主頁。

Rgrds

+0

顯示您的web.xml和調度程序。您是否在控制檯中發現任何錯誤> – 2014-10-17 06:43:54

+0

@SanKrish請查找更新的帖子! – 2014-10-17 06:54:56

+0

我最近寫了一個關於類似問題的答案[這裏](http://stackoverflow.com/a/26325525/3545273)。 – 2014-10-17 08:37:07

回答

0

正如我在this other post解釋有沒有辦法讓一個彈簧MVC允許直屬根地圖根URL服務資源的控制器。

但是,在您的使用情況下,你的資源是不能直接在根下,這應該足以在你的web.xml文件映射到DispatcherServlet代替/*/的。