表單提交數據丟失的問題


 

在流程審批過程中,提交審批時發現使用request.getParameter(“taskId”)獲取數據時,發現取得任務ID為空。

在調試的過程中我發現表單的數據量特別大。

到網上查詢了一下,說post  提交數據數據量有限制。

 

於是寫了個表單測試了一下:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
    String taskId=request.getParameter("taskId");
    String name=request.getParameter("name");
    System.out.println(taskId);
    
    System.out.println(name);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<form name="frmSubmit" method="post">
<input type="text" name="taskId">
<textarea rows="30" cols="200" name="name"></textarea>
<input type="submit" value="submit">
</form>
</body>
</html>

測試結果是,如果數據超過2MB的時候數據時獲取不到了。是兩個表單都獲取不到數據,然后修改tomcat 連接參數。

<Connector   maxPostSize="0" URIEncoding="utf-8" connectionTimeout="20000"  port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

將maxPostSize修改為0則不顯示post數據大小。

發現還是沒有解決之前的問題。

在調試的過程中發現,服務器打印了如下信息。

信息: More than the maximum number of request parameters (GET plus POST) for a single request ([10,000]) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.

搜索了一下這個告警信息。

原來是服務器對提交的參數做了限制,tomcat 文檔描述如下:

The maximum number of parameters (GET plus POST) which will be automatically parsed by the container. A value of less than 0 means no limit. If not specified, a default of 10000 is used. Note that FailedRequestFilter filter can be used to reject requests that hit the limit.

這個默認值為10000個,如果超過了10000個那么就丟棄。這也就解釋了為什么我把taskId提前到form標簽后,數據能夠獲取到。

知道了 原因:

我們修改tomcat配置如下:

<Connector maxParameterCount="-1"  maxPostSize="0" URIEncoding="utf-8" connectionTimeout="20000"  port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

不限制參數大小和提交數據大小,這樣重新審批就沒有問題了。

 

當然這個解決辦法不是很好,因為他會極大的消耗服務器性能,因為提交的參數超過了10000個。

解決的辦法是不提交那么的表單,這個我們這個表單系統中是可以的。

因為我們沒有必要提交那么多的參數,我們的數據都拼裝成了一個json進行提交,這樣對服務器性能會 有極大的提升。

將我們的程序修改成使用ajaxpost的方式提交,只提交部分參數就可以了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM