L
L
Loligan2016-05-10 05:36:22
Java
Loligan, 2016-05-10 05:36:22

How do I upload images if I have mapped the folder where they are stored using Spring MVC?

Uploaded files via:

@Controller
public class FileController {

    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    @ResponseBody
    public String uploadFile(@RequestParam("file") MultipartFile file) {
 ...

Everything was downloading fine until I needed to view these images and images in general (they are stored in webapp / images. And it was decided to map this folder:
In spring-context.xml I added the following:
<mvc:resources mapping="/images/*" location="/images/" />

Now I can view any images that are in the folder, but I can’t upload images to this folder, and indeed anywhere else. Throws an error page.
PS And in general, it also does not allow any pages.
All spring-context.xml
<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" 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.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.xsd">
    <mvc:resources mapping="/images/*" location="/images/**" />
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="20000000" />
    </bean>
    <context:annotation-config/>
    <context:component-scan base-package="project.photohosting"/>

</beans>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Loligan, 2016-05-10
@Loligan

Understood. Should have written before
<mvc:annotation-driven />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question