2014-10-17 250 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代替/*/的。