2

我正在尝试将其实施我的项目中。我将在里面有一个本地资源C:\resource\pdf\

更新:

我之前的配置运行良好:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <context:component-scan base-package="com.neu.als.thesis.web.controllers" />

  <!--  Resolves view names to protected .jsp resources within the /WEB-INF/views directory --> 
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/" />
    <property name="suffix" value=".jsp" />
  </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="10000000"/>
  </bean>

</beans>

并修改它以实现本地资源:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context" 
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd
   http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

  <context:component-scan base-package="com.neu.als.thesis.web.controllers" />

  <mvc:resources mapping="/picture/**" location="file:/resource/" />

  <!--  Resolves view names to protected .jsp resources within the /WEB-INF/views directory --> 
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/" />
    <property name="suffix" value=".jsp" />
  </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="10000000"/>
  </bean>

</beans>

但是当我运行该项目时,404会引发错误。我控制台的最后几行是:

Nov 02, 2013 8:12:21 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ThesisProject/] in DispatcherServlet with name 'ThesisProject'

似乎无法找到默认控制器。我错过了什么?

更新 2

这是我的 servlet 定义web.xml

<!-- Servlet definition -->
  <servlet>
      <servlet-name>ThesisProject</servlet-name>
      <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
      </servlet-class>
      <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
      <servlet-name>ThesisProject</servlet-name>
      <url-pattern>*.do</url-pattern>
  </servlet-mapping>

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

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

2 回答 2

4

你可以试试

 mvc:resources mapping="/picture/**" location="file:///C:/resource/pdf" />

请求您的资源,例如

 servlermappingmvc/picture/pdf/mypdf.pdf

更新

您可以将 servlet-mapping .do 更改为 /controller/

于 2013-11-02T12:28:20.170 回答
0
Nov 02, 2013 8:12:21 PM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/ThesisProject/] in DispatcherServlet with name 'ThesisProject'

您是否可能已将应用程序部署在 Web 容器的根上下文路径中?

您可以尝试使用下载文件http://localhost:8080/picture/pdf/test.pdf吗?

于 2013-11-02T13:19:21.480 回答