javapost⼤⽂件_POST请求数据量过⼤解决⽅案_JAVA String param = StreamToString(getRequest()); // 接收参数转成字符串
Map params = UrlParams(param); // 将字符串参数转Map
import org.apachemons.lang3.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class ParamsUtil {
/**
* 将url参数转换成map
* @param param aa=11&bb=22&cc=33
* @return
*/
public static Map getUrlParams(String param) {
Map map = new HashMap<>(0);
if (StringUtils.isBlank(param)) {
return map;
}
String[] params = param.split("&");
for (int i = 0; i < params.length; i++) {
int index = params[i].indexOf("=");
if (index != -1) {
map.put(params[i].substring(0, index), params[i].substring(index+1));
}
}
return map;
}
/**
* 将map转换成url
* @param map
* @return
*/
public static String getUrlParamsByMap(Map map) {
if (map == null) {
return "";
}
StringBuffer sb = new StringBuffer();
for (Map.Entry entry : Set()) {
sb.Key() + "=" + Value());
sb.append("&");
}
String s = sb.toString();
if (s.endsWith("&")) {
s = org.apachemons.lang.StringUtils.substringBeforeLast(s, "&");
}
return s;
}
/**
* 以流的⽅式接收参数, 并转成字符串
* @param request
* @return
*/
public static String getStreamToString(HttpServletRequest request) {
try {
InputStream inputStream;
inputStream = InputStream();
大文件发送//建⽴接收流缓冲,准备处理
StringBuffer requestBuffer = new StringBuffer();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "utf-8")); //读⼊流,并转换成字符串
String readLine;
while ((readLine = adLine()) != null) {
requestBuffer.append(readLine);
}
reader.close();
return java.URLDecoder.String(), "utf-8"); } catch(Exception e) {
e.printStackTrace();
return "";
}
}
}
还有⼀种说法是修改tomcat配置⽂件
maxPostSize="-1"  // tomcat7+
maxPostSize="0"  // tomcat7-