java-隐藏@ModelAttribute变量以防止出现在URL中?春季MVC

前端之家收集整理的这篇文章主要介绍了java-隐藏@ModelAttribute变量以防止出现在URL中?春季MVC 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在使用Spring MVC 3,并且具有以下控制器

@RequestMapping(value="FileUploadForm",method=RequestMethod.GET)
public String showForm(ModelMap model){
    UploadForm form = new UploadForm();
    model.addAttribute("FORM",form);
    return "FileUploadForm";
}

@RequestMapping(value="FileUploadForm",method=RequestMethod.POST)
public ModelAndView processForm(@modelattribute(value="FORM") UploadForm form,BindingResult result){
    if(!result.hasErrors()){
        FileOutputStream outputStream = null;
        String filePath = System.getProperty("java.io.tmpdir") + "/" + form.getFile().getOriginalFilename();
        try {
            outputStream = new FileOutputStream(new File(filePath));
            outputStream.write(form.getFile().getFileItem().get()); 
            outputStream.close();
            System.out.println(form.getName());


             return new ModelAndView(new RedirectView("success?Filepath="+filePath,true,false));
        } catch (Exception e) {
            System.out.println("Error while saving file");
            return new ModelAndView("FileUploadForm");
        }

    }else{
        return new ModelAndView("FileUploadForm");
    }

}

该控制器获取文件路径并用于执行爆炸

@RequestMapping(value="success")
public String blasta(@modelattribute("Filepath") String filepath,Model model){
    Blast sb = new Blast("somepath");
    String[] blastIt = sb.blast("somepath",filepath);
    String newLine = System.getProperty("line.separator");
    ArrayList<Object> result = new ArrayList<>();

    for (int i = 5; i < blastIt.length; i++) {
        if(blastIt[i].startsWith("Lambda")){
            break;
        } else {
            seila.add(blastIt[i]);
            System.out.println(blastIt[i]);
        }
        model.addAttribute("RESULT",result);

    }      
    File f1 = new File(filepath);
    f1.delete();
    return "success";

}

一切正常,但是我仍然在url中获得文件路径.

http://localhost:8081/Ambase/success?Filepath=filePath

如果可能的话,我想这样

http://localhost:8081/Ambase/success
最佳答案
尝试将此代码添加到servlet-config.xml

<mvc:annotation-driven ignoreDefaultModelOnRedirect="true" />
原文链接:https://www.f2er.com/spring/531841.html

猜你在找的Spring相关文章