Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我能';无法从.jsp中找到错误_Java_Jsp_Controller - Fatal编程技术网

Java 我能';无法从.jsp中找到错误

Java 我能';无法从.jsp中找到错误,java,jsp,controller,Java,Jsp,Controller,我不明白为什么这样不行。这就是让我产生问题的jsp。我遵循youtube上的教程,我的jsp看起来与视频中的jsp相同。我改编了视频中的代码,但我认为这不是问题所在,因为控制器和jsp与视频中的相同。 上传页面 上传 那是我的控制器 @Controller public class CsvController { @Autowired FileValidator fileValidator; @Autowired CsvServices csvServices; @RequestM

我不明白为什么这样不行。这就是让我产生问题的jsp。我遵循youtube上的教程,我的jsp看起来与视频中的jsp相同。我改编了视频中的代码,但我认为这不是问题所在,因为控制器和jsp与视频中的相同。


上传页面

上传
那是我的控制器

@Controller
public class CsvController {

@Autowired
FileValidator fileValidator;

@Autowired
CsvServices csvServices;

@RequestMapping(value = "/uploadPage", method = RequestMethod.GET)
public ModelAndView getPage() {
    ModelAndView model = new ModelAndView("upload_page");
    FileUpload formUpload = new FileUpload();
    model.addObject("formUpload", formUpload);

    return model;
}

@RequestMapping (value="/doUpload", method=RequestMethod.POST)
public String doUpload(@ModelAttribute("formUpload") FileUpload fileUpload, BindingResult result, RedirectAttributes redirectAttributes ) throws IOException {
    fileValidator.validate(fileUpload, result);

    if(result.hasErrors()) {
        return "uploadPage";
    } else {
        redirectAttributes.addFlashAttribute("fileNames", uploadAndImportDb(fileUpload));

        return "redirect:/succes";
    }
}

@RequestMapping(value = "/succes", method = RequestMethod.GET)
public ModelAndView succes() {
    ModelAndView model = new ModelAndView("succes");
    return model;
}

private List<String> uploadAndImportDb(FileUpload fileUpload) throws IOException{
    List<String> fileNames = new ArrayList<String>();
    List<String> paths = new ArrayList<String>();
    CommonsMultipartFile[] commonsMultipartFiles = fileUpload.getFiles();

    String filePath = null;

    for(CommonsMultipartFile multipartFile : commonsMultipartFiles) {
        filePath = "C:\\Users\\bogda\\Desktop\\input\\" + multipartFile.getOriginalFilename();
        File file = new File(filePath);

        FileCopyUtils.copy(multipartFile.getBytes(), file);
        fileNames.add(multipartFile.getOriginalFilename());

        paths.add(filePath);
    }

    //parse and import
    csvServices.process(paths);

    return fileNames;
}
}
@控制器
公共类CSV控制器{
@自动连线
文件验证程序文件验证程序;
@自动连线
CSV服务CSV服务;
@RequestMapping(value=“/uploadPage”,method=RequestMethod.GET)
公共模型和视图getPage(){
ModelAndView model=新ModelAndView(“上传页面”);
FileUpload formUpload=新建FileUpload();
model.addObject(“formUpload”,formUpload);
收益模型;
}
@RequestMapping(value=“/doUpload”,method=RequestMethod.POST)
公共字符串doUpload(@modeldattribute(“formUpload”)FileUpload FileUpload,BindingResult result,RedirectAttributes RedirectAttributes)引发IOException{
验证(文件上传,结果);
if(result.hasErrors()){
返回“上传页面”;
}否则{
addFlashAttribute(“文件名”,uploadAndImportDb(fileUpload));
返回“重定向:/success”;
}
}
@RequestMapping(value=“/succes”,method=RequestMethod.GET)
公共模型和视图成功(){
ModelAndView模型=新的ModelAndView(“成功”);
收益模型;
}
私有列表上载导入数据库(文件上载文件上载)引发IOException{
列表文件名=新的ArrayList();
列表路径=新的ArrayList();
CommonMultipartFile[]CommonMultipartFiles=fileUpload.getFiles();
字符串filePath=null;
for(CommonsMultipartFile多部分文件:commonsMultipartFiles){
filePath=“C:\\Users\\bogda\\Desktop\\input\\”+multipartFile.getOriginalFilename();
文件文件=新文件(文件路径);
FileCopyUtils.copy(multipartFile.getBytes(),file);
add(multipartFile.getOriginalFilename());
添加(文件路径);
}
//解析和导入
进程(路径);
返回文件名;
}
}

请在
WEb\u INF/lib
文件夹中添加commons-fileupload-x.x.jar。

您部署jsp/controller的方式是否可能重复?您是否使用Maven构建战争并部署战争?非常感谢,这就是问题所在欢迎…愉快的编码
@Controller
public class CsvController {

@Autowired
FileValidator fileValidator;

@Autowired
CsvServices csvServices;

@RequestMapping(value = "/uploadPage", method = RequestMethod.GET)
public ModelAndView getPage() {
    ModelAndView model = new ModelAndView("upload_page");
    FileUpload formUpload = new FileUpload();
    model.addObject("formUpload", formUpload);

    return model;
}

@RequestMapping (value="/doUpload", method=RequestMethod.POST)
public String doUpload(@ModelAttribute("formUpload") FileUpload fileUpload, BindingResult result, RedirectAttributes redirectAttributes ) throws IOException {
    fileValidator.validate(fileUpload, result);

    if(result.hasErrors()) {
        return "uploadPage";
    } else {
        redirectAttributes.addFlashAttribute("fileNames", uploadAndImportDb(fileUpload));

        return "redirect:/succes";
    }
}

@RequestMapping(value = "/succes", method = RequestMethod.GET)
public ModelAndView succes() {
    ModelAndView model = new ModelAndView("succes");
    return model;
}

private List<String> uploadAndImportDb(FileUpload fileUpload) throws IOException{
    List<String> fileNames = new ArrayList<String>();
    List<String> paths = new ArrayList<String>();
    CommonsMultipartFile[] commonsMultipartFiles = fileUpload.getFiles();

    String filePath = null;

    for(CommonsMultipartFile multipartFile : commonsMultipartFiles) {
        filePath = "C:\\Users\\bogda\\Desktop\\input\\" + multipartFile.getOriginalFilename();
        File file = new File(filePath);

        FileCopyUtils.copy(multipartFile.getBytes(), file);
        fileNames.add(multipartFile.getOriginalFilename());

        paths.add(filePath);
    }

    //parse and import
    csvServices.process(paths);

    return fileNames;
}
}