0

我已经在 stackoverflow 上看到了其他解决方案,但它没有帮助。我正在做同样的事情,但我不知道为什么它不适合我。

我正在 ubuntu 机器上的 /home/images 文件夹和 spring-servlet.xml 中上传图像,我写了以下几行

  <mvc:resources mapping="/resources/**" location="/resources/" /> 

<mvc:resources mapping="/images/**" location="file:/home/images/"/>
<mvc:default-servlet-handler/>

图片正在上传到 /home/images/ 文件夹,但我无法访问这些图片

在 JSP 中我写过

   <img src="/images/image.jpg"/>

但它没有显示这个图像我不明白这里的问题。请让我知道是否需要其他任何内容。

- -更新 - -

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



<context:annotation-config />   

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

<!-- Enable annotation driven controllers, validation etc... -->
<mvc:annotation-driven />

<mvc:resources mapping="/resources/**" location="/resources/" /> 

<mvc:resources mapping="/images/**" location="file:/home/images/"/>
<mvc:default-servlet-handler/>



<!-- Declare a datasource that has pooling capabilities -->
<bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close" p:driverClass="com.mysql.jdbc.Driver"
p:jdbcUrl="jdbc:mysql://localhost/dbtest" p:user="root" p:password="root"
p:acquireIncrement="10" p:idleConnectionTestPeriod="60" p:maxPoolSize="100"
p:maxStatements="50" p:minPoolSize="10" />
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="datasource" />


<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="datasource" />
</bean>

<!-- scan for mappers and will automatically scan the whole classpath for xmls -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="sqlSessionFactory" ref="sqlSessionFactory" />
    <property name="basePackage" value="com.mycom.myproject.db.mybatis.dao" />
</bean>  

<!-- Configure the multipart resolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- one of the properties available; the maximum file size in bytes -->
    <property name="maxUploadSize" value="100000"/>
</bean> 

<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
   p:extractValueFromSingleKeyModel="true" />

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:project-config" />
</bean>

Web.xml

 <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>

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

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring-servlet.xml,
        /WEB-INF/spring-security.xml
    </param-value>
</context-param>


<!-- Spring Security -->
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

 <session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
4

1 回答 1

3

oooook,您的调度程序 servlet 已映射到.htm,因此您的调度程序 servlet 永远不会被调用,因为它处理这些 /resources/ * 请求并调用 ResourceHttpRequestHandler 来写入静态内容。

于 2012-09-11T14:37:00.753 回答