I am having an issue where calling request.getParameter() returns null when large amounts of data are passed to the page. The header Content-Type is application/x-www-form-urlencoded. And the setting for maximum POST size is set to 12,582,912 bytes (i.e. maxPostSize=12582912) in server.xml.
Client Code
public class Send { public static int readTimeout = 30000; public static int connectionTimeout = 10000; public static void main(String[] args) throws IOException, JSONException { sendFile(1000,1); } public static void sendFile(int n,int m) throws IOException, JSONException { String urlStr = "http://localhost:8080/sendChange"; URL url = new URL(urlStr); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); httpConn.setConnectTimeout(connectionTimeout); httpConn.setReadTimeout(readTimeout); httpConn.setRequestMethod("POST"); httpConn.setDoOutput(true); httpConn.setDoInput(true); httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); JSONArray list; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < m; i++) { list = new JSONArray(); for (int j = 0; j < n; j++) { list.put(getChange()); } if(i==0) { stringBuilder.append("bulk="); } else { stringBuilder.append("&bulk_").append(i).append("="); } stringBuilder.append(list.toString()); } int length = stringBuilder.toString().getBytes().length; System.out.println(length); httpConn.setRequestProperty("Content-Length", Integer.toString(stringBuilder.toString().getBytes().length)); DataOutputStream printout = new DataOutputStream(httpConn.getOutputStream()); printout.write(stringBuilder.toString().getBytes()); printout.close(); int responseCode = httpConn.getResponseCode(); System.out.println(responseCode); } Server Code
import org.json.JSONArray; import org.json.JSONException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * Created by mohan-4019 on 12/28/16. */ @WebServlet(name = "CollectorServlet") public class CollectorServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String bulk = request.getParameter("bulk"); try { JSONArray bulkJSON = new JSONArray(bulk); int length = bulkJSON.length(); } catch (JSONException e) { System.out.println(e); } } } The call to getChange() returns a JSONObject, which has size 7kb. It works perfectly for data with small size. Large data can read from request.getInputStream().