有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java组织。springframework。网状物绑定参数的MissingServletRequestParameterException

我在SpringMVC项目中工作

我能够在本地运行我的项目,没有任何问题。我用controller做了一个文件上传页面

虽然我将其用于生产,但我无法得到结果和错误

"org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'userId' is not present

我的代码:(我正在上传屏幕中获取此用户Id)

@Resource
private UserService userService;


@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    Long userId = userService.getLoggedInUser(request).getId();

    ModelAndView modelAndView = new ModelAndView(UploadDocView.uploadmain);
    modelAndView.addObject("userId", userId);
    return modelAndView;
}

上传jsp

<form method="POST" enctype="multipart/form-data" action="upload.htm">
    File to upload: 
    <input type="file" name="file"><br /> 

    <input type="hidden" name="userId" value="${userId}"><br /> <br />

    <input type="submit" value="Upload">
</form>

文件上传控制器

@Controller
public class FileUploadController {

    @Resource
    private CollectionsRepository collectionsRepository;

    @RequestMapping(value="/upload", method=RequestMethod.GET)
        public @ResponseBody String provideUploadInfo() {
            return "You can upload a file by posting to this same URL.";
        }

        @RequestMapping(value="/upload.htm", method=RequestMethod.POST)
        public ModelAndView handleFileUpload(@RequestParam("userId") String userId, @RequestParam("file") MultipartFile file){
            if (!file.isEmpty()) {
                try {
                    String filePath = "/home/ubuntu/analyzer/LOS/";
                    byte[] bytes = file.getBytes();
                    File newFile = new File(filePath+""+file.getOriginalFilename());
                    BufferedOutputStream stream =
                            new BufferedOutputStream(new FileOutputStream(newFile));
                    stream.write(bytes);
                    stream.close();

                    List<BankStatementError> errorList = new ArrayList<BankStatementError>();

                    Excelsheetreader esr = new Excelsheetreader();
                    List<String> listaddSN = esr.GetCalculation(Long.parseLong(userId), filePath+""+file.getOriginalFilename());

                    newFile.delete();

                    for (int i = 0; i < listaddSN.size(); i++) {
                        String bank = listaddSN.get(i);
                        BankStatementError error = collectionsRepository.getErrorByBank(bank);
                        errorList.add(error);
                    }

                    ModelAndView modelAndView = new ModelAndView(UploadDocView.uploadsuccess);
                    modelAndView.addObject("errorList", errorList);
                    return modelAndView;
                } catch (Exception e) {
                    ModelAndView modelAndView = new ModelAndView(UploadDocView.uploadexecption);
                    return modelAndView;
                }
            } else {
                ModelAndView modelAndView = new ModelAndView(UploadDocView.uploadempty);
                return modelAndView;
            }
        }
}

问题是userId是空的,我认为这是上传屏幕的问题。但不确定。有人能给我指出一条正确的路吗


共 (0) 个答案