jettytomcat对待表单过长问题
生活随笔
收集整理的這篇文章主要介紹了
jettytomcat对待表单过长问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為什么80%的碼農都做不了架構師?>>> ??
結論兩句話:
?
tomcat知道自己處理不了了,什么也不干過去了
jett知道自己處理不了了,拋個IllegalStateException出來通知一下
jetty默認允許的content-length=200×1000
org.eclipse.jetty.server.Request public void extractParameters(){if (_baseParameters == null) _baseParameters = new MultiMap(16);if (_paramsExtracted) {if (_parameters==null)_parameters=_baseParameters;return;}_paramsExtracted = true; ....// handle any _content.String encoding = getCharacterEncoding();String content_type = getContentType();if (content_type != null && content_type.length() > 0){content_type = HttpFields.valueParameters(content_type, null);if (MimeTypes.FORM_ENCODED.equalsIgnoreCase(content_type) &&(HttpMethods.POST.equals(getMethod()) || HttpMethods.PUT.equals(getMethod()))){int content_length = getContentLength();if (content_length != 0){try{int maxFormContentSize=-1;if (_context!=null)maxFormContentSize=_context.getContextHandler().getMaxFormContentSize();else{Integer size = (Integer)_connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");if (size!=null)maxFormContentSize =size.intValue();}if (content_length>maxFormContentSize && maxFormContentSize > 0){throw new IllegalStateException("Form too large"+content_length+">"+maxFormContentSize);}InputStream in = getInputStream();// Add form params to query paramsUrlEncoded.decodeTo(in, _baseParameters, encoding,content_length<0?maxFormContentSize:-1);}catch (IOException e){if (Log.isDebugEnabled())Log.warn(e);elseLog.warn(e.toString());}}}} ....} }?
jetty修改content-length方法
?
<Configure id="Server" class="org.eclipse.jetty.server.Server"> ... <Call name="setAttribute"><Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg><Arg><SystemProperty name="org.eclipse.jetty.server.Request.maxFormContentSize" default="200000"/></Arg></Call> ... </Configure>啟動方式
?
java -jar start.jar -Dorg.eclipse.jetty.server.Request.maxFormContentSize=600000還有另外一種配置方式
?
<Call class="java.lang.System" name="setProperty"><Arg>org.eclipse.jetty.server.Request.maxFormContentSize</Arg><Arg>400000</Arg> </Call> ?tomcat默認允許的content-length=2×1024×1024
org.apache.catalina.connector.Request protected void parseParameters() { ......if (!("application/x-www-form-urlencoded".equals(contentType)))return;int len = getContentLength(); if (len > 0) {int maxPostSize = connector.getMaxPostSize(); // tomcat默認大小2*1024*1024 if ((maxPostSize > 0) && (len > maxPostSize)) {if (context.getLogger().isDebugEnabled()) {context.getLogger().debug(sm.getString("coyoteRequest.postTooLarge"));}return; // 內容超長則直接返回,jetty會拋出IllegalStateException//Parameters 對象沒有內容} ..... }public Map<String, String[]> getParameterMap() {if (parameterMap.isLocked())return parameterMap;Enumeration<String> enumeration = getParameterNames();while (enumeration.hasMoreElements()) {String name = enumeration.nextElement();String[] values = getParameterValues(name);parameterMap.put(name, values);}parameterMap.setLocked(true);return parameterMap; }public Enumeration<String> getParameterNames() {if (!parametersParsed)parseParameters();return coyoteRequest.getParameters().getParameterNames(); }轉載于:https://my.oschina.net/boltwu/blog/533742
總結
以上是生活随笔為你收集整理的jettytomcat对待表单过长问题的全部內容,希望文章能夠幫你解決所遇到的問題。