Solucionado (ver solução)
Solucionado
(ver solução)
9
respostas

aula 8- envio de arquivos ao servidor

Galera, criei a paste dentro de src/main/webapp e ainda assim o FileNotFound persiste

alguma ideia ?

jan 22, 2016 1:59:27 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/SpringMvc] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: jav a.io.IOException: java.io.FileNotFoundException: C:\Users\viniciusbraga\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SpringMvc\arquivos-sumario\conversa OraclusterNovo.png (The system cannot find the path specified)] with root cause java.io.FileNotFoundException: C:\Users\viniciusbraga\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SpringMvc\arquivos-sumario\conversaOraclusterNovo.png (The system cannot find the path specified) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.(Unknown Source) at java.io.FileOutputStream.(Unknown Source) at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.write(DiskFileItem.java:402) at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:119) at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile.transferTo(StandardMultipartHttpServletRequest.java:258) at org.SpringMvc.loja.infra.Filesaver.write(Filesaver.java:29) at org.SpringMvc.loja.controller.ProdutosController.gravar(ProdutosController.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExec

9 respostas

``` an 22, 2016 3:02:27 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/SpringMvc] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: jav a.io.IOException: java.io.FileNotFoundException: C:\Users\viniciusbraga\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SpringMvc\arquivos-sumario\Juliana. png (The system cannot find the path specified)] with root cause java.io.FileNotFoundException: C:\Users\viniciusbraga\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SpringMvc\arquivos-sumario\Juliana.png (The system ca nnot find the path specified) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.(Unknown Source) at java.io.FileOutputStream.(Unknown Source) at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.write(DiskFileItem.java:402) at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:119) at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile.transferTo(StandardMultipartHttpServletRequest.java:258) at org.SpringMvc.loja.infra.Filesaver.write(Filesaver.java:29) at org.SpringMvc.loja.controller.ProdutosController.gravar(ProdutosController.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)````

an 22, 2016 3:02:27 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/SpringMvc] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: jav a.io.IOException: java.io.FileNotFoundException: C:\Users\viniciusbraga\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SpringMvc\arquivos-sumario\Juliana. png (The system cannot find the path specified)] with root cause java.io.FileNotFoundException: C:\Users\viniciusbraga\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\SpringMvc\arquivos-sumario\Juliana.png (The system ca nnot find the path specified) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(Unknown Source) at java.io.FileOutputStream.<init>(Unknown Source) at org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.write(DiskFileItem.java:402) at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:119) at org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile.transferTo(StandardMultipartHttpServletRequest.java:258) at org.SpringMvc.loja.infra.Filesaver.write(Filesaver.java:29) at org.SpringMvc.loja.controller.ProdutosController.gravar(ProdutosController.java:60) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863) at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

Oi Vinicius,

Como você está fazendo no código? Poderia colocar o código aqui para vermos?

Abraço

no produtosController

....
@Autowired
    private Filesaver filesaver;
    ....
@RequestMapping(method=RequestMethod.POST)
    public ModelAndView gravar(MultipartFile sumario ,@Valid Produto produto, BindingResult result){



        System.out.println(sumario.getOriginalFilename());

        if(result.hasErrors()){
            return form(produto);
        }

        //seta o arq onde será salvo o sumario-file
        String path = filesaver.write("arquivos-sumario", sumario);
        //seta o arquivo no produto
        produto.setSumarioPath(path);


        produtoDao.gravar(produto);
        return new ModelAndView("redirect:produtos/ok");

    }

no ServletSpringMVC.java

@Override
    protected void customizeRegistration(Dynamic registration) {
        // TODO Auto-generated method stub
        registration.setMultipartConfig(new MultipartConfigElement(""));
    }

AppWebConfiguration.java

....
@Bean
    public MultipartResolver multipartResolver() {
        return new StandardServletMultipartResolver();
    }
....

fileSaver,java

package org.SpringMvc.loja.infra;

import java.io.File;
import java.io.IOException;

import javax.management.RuntimeErrorException;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class Filesaver {

    //cria o a variável para lidar com o request 
    @Autowired
    HttpServletRequest request;

    public String write(String basePath, MultipartFile file){

            try {

                //pega o caminho absoluto do arquivo
                String realPath= request.getServletContext().getRealPath("/"+ basePath);
                String path = realPath + "/" + file.getOriginalFilename();

                //realiza a transferencia
                file.transferTo(new File(path));

                return basePath + "/" + file.getOriginalFilename();

            } catch (IllegalStateException | IOException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException(e);
            } 


    }

}

form.jsp

<div>
            <label>Súmario</label>
            <input type="file" name="sumario" />

        </div>

criei a pasta dentro de src\main\webapp\java e ainda assim o throwna um fileNotFound

no produtosController

....
@Autowired
    private Filesaver filesaver;
    ....
@RequestMapping(method=RequestMethod.POST)
    public ModelAndView gravar(MultipartFile sumario ,@Valid Produto produto, BindingResult result){



        System.out.println(sumario.getOriginalFilename());

        if(result.hasErrors()){
            return form(produto);
        }

        //seta o arq onde será salvo o sumario-file
        String path = filesaver.write("arquivos-sumario", sumario);
        //seta o arquivo no produto
        produto.setSumarioPath(path);


        produtoDao.gravar(produto);
        return new ModelAndView("redirect:produtos/ok");

    }

no ServletSpringMVC.java

@Override
    protected void customizeRegistration(Dynamic registration) {
        // TODO Auto-generated method stub
        registration.setMultipartConfig(new MultipartConfigElement(""));
    }

AppWebConfiguration.java

....
@Bean
    public MultipartResolver multipartResolver() {
        return new StandardServletMultipartResolver();
    }
....

fileSaver,java

package org.SpringMvc.loja.infra;

import java.io.File;
import java.io.IOException;

import javax.management.RuntimeErrorException;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class Filesaver {

    //cria o a variável para lidar com o request 
    @Autowired
    HttpServletRequest request;

    public String write(String basePath, MultipartFile file){

            try {

                //pega o caminho absoluto do arquivo
                String realPath= request.getServletContext().getRealPath("/"+ basePath);
                String path = realPath + "/" + file.getOriginalFilename();

                //realiza a transferencia
                file.transferTo(new File(path));

                return basePath + "/" + file.getOriginalFilename();

            } catch (IllegalStateException | IOException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException(e);
            } 


    }

}

form.jsp

<div>
            <label>Súmario</label>
            <input type="file" name="sumario" />

        </div>

criei a pasta dentro de src\main\webapp\java e ainda assim o throwna um fileNotFound

no produtosController

....
@Autowired
    private Filesaver filesaver;
    ....
@RequestMapping(method=RequestMethod.POST)
    public ModelAndView gravar(MultipartFile sumario ,@Valid Produto produto, BindingResult result){



        System.out.println(sumario.getOriginalFilename());

        if(result.hasErrors()){
            return form(produto);
        }

        //seta o arq onde será salvo o sumario-file
        String path = filesaver.write("arquivos-sumario", sumario);
        //seta o arquivo no produto
        produto.setSumarioPath(path);


        produtoDao.gravar(produto);
        return new ModelAndView("redirect:produtos/ok");

    }

no ServletSpringMVC.java

@Override
    protected void customizeRegistration(Dynamic registration) {
        // TODO Auto-generated method stub
        registration.setMultipartConfig(new MultipartConfigElement(""));
    }

AppWebConfiguration.java

....
@Bean
    public MultipartResolver multipartResolver() {
        return new StandardServletMultipartResolver();
    }
....

fileSaver,java

package org.SpringMvc.loja.infra;

import java.io.File;
import java.io.IOException;

import javax.management.RuntimeErrorException;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class Filesaver {

    //cria o a variável para lidar com o request 
    @Autowired
    HttpServletRequest request;

    public String write(String basePath, MultipartFile file){

            try {

                //pega o caminho absoluto do arquivo
                String realPath= request.getServletContext().getRealPath("/"+ basePath);
                String path = realPath + "/" + file.getOriginalFilename();

                //realiza a transferencia
                file.transferTo(new File(path));

                return basePath + "/" + file.getOriginalFilename();

            } catch (IllegalStateException | IOException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException(e);
            } 


    }

}

form.jsp

<div>
            <label>Súmario</label>
            <input type="file" name="sumario" />

        </div>

criei a pasta dentro de src\main\webapp\java e ainda assim o throwna um fileNotFound

no produtosController

....
@Autowired
    private Filesaver filesaver;
    ....
@RequestMapping(method=RequestMethod.POST)
    public ModelAndView gravar(MultipartFile sumario ,@Valid Produto produto, BindingResult result){



        System.out.println(sumario.getOriginalFilename());

        if(result.hasErrors()){
            return form(produto);
        }

        //seta o arq onde será salvo o sumario-file
        String path = filesaver.write("arquivos-sumario", sumario);
        //seta o arquivo no produto
        produto.setSumarioPath(path);


        produtoDao.gravar(produto);
        return new ModelAndView("redirect:produtos/ok");

    }

no ServletSpringMVC.java

@Override
    protected void customizeRegistration(Dynamic registration) {
        // TODO Auto-generated method stub
        registration.setMultipartConfig(new MultipartConfigElement(""));
    }

AppWebConfiguration.java

....
@Bean
    public MultipartResolver multipartResolver() {
        return new StandardServletMultipartResolver();
    }
....

fileSaver,java

package org.SpringMvc.loja.infra;

import java.io.File;
import java.io.IOException;

import javax.management.RuntimeErrorException;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

@Component
public class Filesaver {

    //cria o a variável para lidar com o request 
    @Autowired
    HttpServletRequest request;

    public String write(String basePath, MultipartFile file){

            try {

                //pega o caminho absoluto do arquivo
                String realPath= request.getServletContext().getRealPath("/"+ basePath);
                String path = realPath + "/" + file.getOriginalFilename();

                //realiza a transferencia
                file.transferTo(new File(path));

                return basePath + "/" + file.getOriginalFilename();

            } catch (IllegalStateException | IOException e) {
                // TODO Auto-generated catch block
                throw new RuntimeException(e);
            } 


    }

}

form.jsp

<div>
            <label>Súmario</label>
            <input type="file" name="sumario" />

        </div>

criei a pasta dentro de src\main\webapp\java e ainda assim o throwna um fileNotFound

solução!

observando outro post semelhante aqui no forum, realizei o seguinte procedimento:

1- coloquei o endereço "hardcoded" //String realPath= "C:\Users\viniciusbraga\git\SpringMvc\src\main\webapp\arquivos-sumario";

2- depois comentei e coloquei as linhas anteriormente inseridas.

```String write(String basePath, MultipartFile file){

       try {

         //pega o caminho absoluto do arquivo
         String realPath= request.getServletContext().getRealPath("/" + basePath);
         //String realPath= "C:\Users\viniciusbraga\git\SpringMvc\src\main\webapp\arquivos-sumario";
         String path = realPath + "/" + file.getOriginalFilename();

         //realiza a transferencia
         file.transferTo(new File(path));

         System.out.println(basePath + "/" + file.getOriginalFilename());
         return basePath + "/" + file.getOriginalFilename();


       } catch (IllegalStateException | IOException e) {
         // TODO Auto-generated catch block
         throw new RuntimeException(e);
       }

```

milagrosamente, resolveu o problema...só nao entendi o porquê

uso máquina windows 7 64bits.

Oi Vinícius,

O que acontece é que com o caminho direto ele consegue achar a pasta indo pelo sistema operacional. O problema dessa configuração é que você fica preso a uma pasta específica no seu computador, e quando o sistema for para produção provavelmente será outra pasta.

Vamos tentar outra configuração. Na ABA Servers do Eclipse, clique com o botão direito no Tomcat e escolha -> Add and Remove...

Remova todas as aplicações que estiverem no Tomcat. Agora, clique novamente com o botão direito no Tomcat e escolha a opção -> Clean...

Clique duas vezes em cima do Tomcat e vamos ao abrir a tela de configuração, vamos alterar a opção Server Locations escolhendo a opção Use tomcat installation.

Salve as alterações.

Antes de iniciar o Tomcat, crie uma pastas chamada arquivos-sumario dentro de src/main/webapp.

Vamos ver se temos algum resultado diferente.

Abraço