2

I'm trying to implement this to my project. I'll be having a local resources inside C:\resource\pdf\.

Update:

My previous configuration is working well:

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

And modify it to implement the local resource to this:

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

But when I run the project a 404 error is thrown. And the last few lines at my console is:

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'

Seems the default controller can't be located. What am I missing?

Update 2

here is my servlet definition in 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>
Community
  • 1
  • 1
newbie
  • 1,884
  • 7
  • 34
  • 55

2 Answers2

4

You can try

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

and

request your resource for example with

 servlermappingmvc/picture/pdf/mypdf.pdf

UPDATE

You can change servlet-mapping .do to /controller/

jrey
  • 2,163
  • 1
  • 32
  • 48
  • Sorry if I confused you. My current problem is my default controller can't be detected because of the modification I made in configuration. – newbie Nov 02 '13 at 12:31
  • ok, but you can share your web.xml and anothers configuration resources – jrey Nov 02 '13 at 12:33
  • if only add mvc:resources i think that the resources folder is not found. you can try my answer? – jrey Nov 02 '13 at 12:39
  • I run the project an got `404` and also tried to access through `http://localhost:8080/ThesisProject/picture/pdf/test.pdf` and still `404` exception – newbie Nov 02 '13 at 12:50
  • you can try change your ThesisProject servlet-mapping from asterasterisk.do to /controller/asterisk and then try your pdf with http://localhost:8080/ThesisProject/controller/picture/pdf/test.pdf. your resources configuration is over your Controller Servlet but your request not matches with *.do – jrey Nov 02 '13 at 12:53
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/40423/discussion-between-jrey-py-and-newbie) – jrey Nov 02 '13 at 12:56
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'

Is it possible that you have deployed your application in the root context path of your web container?

Could you try downloading the file using http://localhost:8080/picture/pdf/test.pdf?

Pieter
  • 2,745
  • 14
  • 17