Wicket 6 - Capturing HttpServletRequest parameters in Multipart form?

浪尽此生 提交于 2019-12-02 21:24:58

问题


USing Wicket 6.17 and servlet 2.5, I have a form that allows file upload, and also has ReCaptcha (using Recaptcha4j). When the form has ReCaptcha without file upload, it works properly using the code:

    final HttpServletRequest servletRequest = (HttpServletRequest ) ((WebRequest) getRequest()).getContainerRequest();
    final String remoteAddress = servletRequest.getRemoteAddr();
    final String challengeField = servletRequest.getParameter("recaptcha_challenge_field");
    final String responseField = servletRequest.getParameter("recaptcha_response_field");

to get the challenge and response fields so that they can be validated.

This doesn't work when the form has the file upload because the form must be multipart for the upload to work, and so when I try to get the parameters in that fashion, it fails.

I have pursued trying to get the parameters differently using ServletFileUpload:

    ServletFileUpload fileUpload = new ServletFileUpload(new DiskFileItemFactory(new FileCleaner()) );
    String response = IOUtils.toString(servletRequest.getInputStream());

and

    ServletFileUpload fileUpload = new ServletFileUpload(new DiskFileItemFactory(new FileCleaner()) );
    List<FileItem> requests = fileUpload.parseRequest(servletRequest);

both of which always return empty.

Using Chrome's network console, I see the values that I'm looking for in the Request Payload, so I know that they are there somewhere.

Any advice on why the requests are coming back empty and how to find them would be greatly appreciated.

Update: I have also tried making the ReCaptcha component multipart and left out the file upload. The result is still the same that the response is empty, leaving me with the original conclusion about multipart form submission being the problem.


回答1:


Thanks to the Wicket In Action book, I have found the solution:

MultipartServletWebRequest multiPartRequest = webRequest.newMultipartWebRequest(getMaxSize(), "ignored");
// multiPartRequest.parseFileParts(); // this is needed since Wicket 6.19.0+
IRequestParameters params = multiPartRequest.getRequestParameters();

allows me to read the values now using the getParameterValue() method.



来源:https://stackoverflow.com/questions/26515158/wicket-6-capturing-httpservletrequest-parameters-in-multipart-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!