后期参数变为空(随机)
我的 Web 应用程序是使用 Struts2 开发的,直到最近它都运行良好。突然,其中一个模块开始出现故障。
出现故障的模块是“更新学生详细信息”页面。该页面有很多字段,例如“学校名称”、“学位名称”等。
School 1: <input name="schoolName">
School 2: <input name="schoolName">
.....
School n: <input name="schoolName">
如前所述,该页面直到最近都运行得很好。现在,“schoolName”、“ DegreeName”等的一个/多个值在服务器端以“”(空字符串)形式接收。
为了调试,我在 Eclipse 中使用了 firebug 和远程调试。我发现客户端的后置参数是正确的。例如,在其中一次提交期间,后置参数如下(我从 firebug 中注意到它们)。
Content-Type: multipart/form-data; boundary=---------------------------2921238217421
Content-Length: 48893
<OTHER_PARAMETERS> <!--Truncated for clarity -->
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
ABC Institute
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
Test School
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
XYZ
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
Texas Institute
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
XXXX School
-----------------------------2921238217421--
但在服务器端,请求参数如下:
schoolName=[ABC Institute, Test School, XYZ, , XXXX School],
在这种特殊情况下,“Texas Institute”被接收为“”(空字符串)。这种情况并没有持续发生。变为 NULL(或 EMPTY STRING)的参数对我来说似乎是随机的 - 在一个实例中,参数 schoolName[3] 变为 null,如上所示,参数 schoolName[2] 在另一次提交期间变为 null,等等。有时,没有一个参数无效。
以下是动作定义中的拦截器列表。
List of interceptors:
----------------------
FileUploadInterceptor
org.apache.struts2.interceptor.FileUploadInterceptor
ServletConfigInterceptor
org.apache.struts2.interceptor.ServletConfigInterceptor StaticParametersInterceptor
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor
ParametersInterceptor
com.opensymphony.xwork2.interceptor.ParametersInterceptor
MyCustomInterceptor
com.xxxx.yyyy.interceptors.GetLoggedOnUserInterceptor
这个问题对我来说显得相当奇怪,我无法将问题的确切原因归零。在这方面的任何帮助将不胜感激。提前致谢。
谢谢, 拉古拉姆
My web application is developed with Struts2 and it was working fine till recently. All of a sudden one of the modules has started malfunctioning.
The malfunctioning module is 'Update Student details' page. This page has a lot of fields like 'schoolName', 'degreeName', etc .
School 1: <input name="schoolName">
School 2: <input name="schoolName">
.....
School n: <input name="schoolName">
As mentioned earlier, the page was working perfectly fine till recently. Now, one/many of the values of 'schoolName', 'degreeName', etc are being received as "" (EMPTY STRING) on the server-side.
For debugging, I used firebug and remote-debugging in eclipse. I find that the post-parameters are correct on the client-side. For instance, during one of the submissions the post-parameters were as below (i noted them from firebug).
Content-Type: multipart/form-data; boundary=---------------------------2921238217421
Content-Length: 48893
<OTHER_PARAMETERS> <!--Truncated for clarity -->
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
ABC Institute
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
Test School
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
XYZ
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
Texas Institute
-----------------------------2921238217421
Content-Disposition: form-data; name="schoolName"
XXXX School
-----------------------------2921238217421--
But on the server-side, the request params were as below:
schoolName=[ABC Institute, Test School, XYZ, , XXXX School],
"Texas Institute" was received as "" (EMPTY STRING) in this particular case. This is not happening consistently. The parameters that become NULL (or EMPTY STRING) seem random to me - during one instance, parameter schoolName[3] became null as illustrated above, parameter schoolName[2] became null during yet another submission, etc. At times, none of the parameters are nullified.
The following is the list of the interceptors in the action definition.
List of interceptors:
----------------------
FileUploadInterceptor
org.apache.struts2.interceptor.FileUploadInterceptor
ServletConfigInterceptor
org.apache.struts2.interceptor.ServletConfigInterceptor StaticParametersInterceptor
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor
ParametersInterceptor
com.opensymphony.xwork2.interceptor.ParametersInterceptor
MyCustomInterceptor
com.xxxx.yyyy.interceptors.GetLoggedOnUserInterceptor
This issue appears rather weird to me and I have not been able to zero-in on the exact cause of the issue. Any help in this regard would be highly appreciated. Thanks in advance.
Thanks,
Raghuram
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新。
我的表单发送了一个多部分请求(因为表单上启用了文件上传,所以需要)。我决定记录到达服务器的后期数据。我修改了 RequestDumperFilter.java 以记录多部分发布数据。添加此过滤器后,参数丢失问题似乎已经停止(150 次提交的表单中 0 丢失)。我删除了过滤器并能够再次重现该问题。
谢谢,
拉古拉姆
An update.
My form sends a multipart request (needed since file upload is enabled on the form). I decided to log the post-data that comes to the server. I modified RequestDumperFilter.java to log the multipart post data. After i added this filter, the parameter loss issue seems to have ceased (0 loss out of 150 submissions of form). I removed the filter and was able to reproduce the issue again.
Thanks,
Raghuram
这个 tomcat 错误怎么样: https://issues.apache.org/bugzilla/ show_bug.cgi?id=37794
当 HTTP/1.1 客户端使用传输编码 POST 时:分块到 servlet,
getParameter() 系列和 getQueryString() 方法无法检索
不返回任何内容即可得到正确结果。相反,读取直到文件结尾
在 servlet 输入流上生成正确的结果。
6.0.21 中已修复。
What about this tomcat bug: https://issues.apache.org/bugzilla/show_bug.cgi?id=37794
When an HTTP/1.1 client POST with transfer-encoding: chunked to a servlet,
the getParameter() family and getQueryString() methods fail to retrieve the
correct result by returning nothing. In contrast, reading until end-of-file
on the servlets input stream produces correct result.
The fix is in 6.0.21.