Wicket 6 - 以Multipart形式捕获HttpServletRequest参数? [英] Wicket 6 - Capturing HttpServletRequest parameters in Multipart form?

查看:175
本文介绍了Wicket 6 - 以Multipart形式捕获HttpServletRequest参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Wicket 6.17和servlet 2.5,我有一个允许文件上传的表单,并且还有ReCaptcha(使用Recaptcha4j)。当表单有ReCaptcha而没有文件上传时,它使用代码正常工作:

  final HttpServletRequest servletRequest =(HttpServletRequest)((WebRequest )getRequest())。getContainerRequest(); 
final String remoteAddress = servletRequest.getRemoteAddr();
final字符串challengeField = servletRequest.getParameter(recaptcha_challenge_field);
final String responseField = servletRequest.getParameter(recaptcha_response_field);

来获得询问和回应字段,以便验证它们。

当窗体上传文件时这不起作用,因为窗体必须是多部分才能上传,所以当我尝试获取参数时时尚,它失败了。

我试图使用ServletFileUpload获取不同的参数:

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

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

两者总是会返回空。



使用Chrome的网络控制台,我在Request Payload中看到了我正在查找的值,所以我知道它们在那里。



请求是空的,如何找到他们将不胜感激。

更新:我也试图使ReCaptcha组件多部分,并省略文件上传。结果仍然是响应是空的,留下了多部分表单提交的原始结论是问题。

>感谢Wicket In Action书籍,我找到了解决方案:

pre $ MultipartServletWebRequest multiPartRequest = webRequest.newMultipartWebRequest(getMaxSize(), 忽略);
// multiPartRequest.parseFileParts(); //这是自Wicket 6.19.0+
IRequestParameters params = multiPartRequest.getRequestParameters();

允许我使用getParameterValue()方法读取值。 b

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.

解决方案

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.

这篇关于Wicket 6 - 以Multipart形式捕获HttpServletRequest参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆