Estou com dificuldade em fazzer o upload de arquivo, estou fazendo uma aplicação propria e seguindo os passos do curso!
Estou dois dias tentando resolver este problema e nada =(
Ainda não estou jogando o nome do arquivo no banco de dados. Primeiramente estou tentando passar o arquivo para o servidor!
IMAGENS DE ERRO
http://imgur.com/a/MoTst, http://imgur.com/a/Isd0D
SEGUE OS CODIGOS
CONTROLLER
package br.com.degustaju.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import br.com.degustaju.dao.FotosDao;
import br.com.degustaju.infra.FileSaver;
@Controller
public class FotosController{
private FotosDao dao;
private static final Logger logger = LoggerFactory.getLogger(FotosController.class);
@Autowired
private FileSaver fileSaver;
@Autowired
public FotosController(FotosDao dao){
this.dao = dao;
}
@RequestMapping(value="/uploadfoto", method = RequestMethod.POST)
public ModelAndView gravar(MultipartFile sumario, BindingResult result, RedirectAttributes redirectAttributes){
String path = fileSaver.write("arquivos-sumario", sumario);
return new ModelAndView("redirect:produtos");
}
}
APPWEBCONFIGURATION
package br.com.degustaju.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import br.com.degustaju.controller.FotosController;
import br.com.degustaju.dao.FotosDao;
import br.com.degustaju.infra.FileSaver;
@EnableWebMvc
@ComponentScan(basePackageClasses={FotosController.class, FotosDao.class, FileSaver.class})
public class AppWebConfiguration {
@Bean
public MultipartResolver multipartResolver(){
return new StandardServletMultipartResolver();
}
}
SERVLETSPRINGMVC
package br.com.degustaju.config;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class ServletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected void customizeRegistration(Dynamic registration) {
registration.setMultipartConfig(new MultipartConfigElement(""));
}
@Override
protected Class<?>[] getRootConfigClasses() {
// TODO Auto-generated method stub
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
// TODO Auto-generated method stub
return null;
}
@Override
protected String[] getServletMappings() {
// TODO Auto-generated method stub
return null;
}
}
HTML
<%@ include file="/WEB-INF/views/includes/header.jsp"%>
<div class="conteudo">
<h1>Fotos</h1>
<div class="form-group">
<form action="/degustaju/uploadfoto" enctype="multipart/form-data" method="POST">
<input type="file" name="sumario" id="file" class="inputfile" multiple="multiple"/>
<label for="file" class="file-config" id=""><i class="fa fa-download" aria-hidden="true"></i><br>Selecione as Fotos</label>
<span id="response">
<div class="progress">
<div class="progress-bar" role="progressbar" aria-valuenow="0"
aria-valuemin="0" aria-valuemax="100" style="width:0">
<span class="sr-only">70% Complete</span>
</div>
</div>
</span>
<input type="submit">
</form>
</div>
<div class="box-xl box-fotos"></div>
</div>
<%@ include file="/WEB-INF/views/includes/rodape.jsp"%>
<script>
</script>