今天在使用Eclipse的Jetty插件做為服務器提交富文本編輯中的數據時,報如下異常:
在\eclipse\plugins目錄下,找到org.mortbay.jetty.server_6.1.23.v201012071420.jar包,扔進JD-GUI中,根據報錯提示信息org.morbay.jetty.Request.extractParameters()方法中找到如下信息:
注意觀察箭頭所示部分,異常應該是這兒拋出來的,但maxFormContentSize值是從那里來的呢,依據this._context.getContextHandler().getMaxFormContentSize()這句提示,找到org.mortbay.jetty.handlerContextHandler.class類,結果發現該類中有如下一句,興奮,默認值在此。
那么這個默認值是設置好的,如何修改呢,通過看Request類里的this._context.getContextHandler().getMaxFormContentSize()代碼,繼續追蹤,該值應該是從WEB的入口獲取的即web.xml,但是這個值如何傳進去呢,經過網上的搜索與實踐,可以在WEB-INF目錄下新建一個jetty-web.xml文件,里面寫如下內容,對maxFormContentSize重新賦值即可(Jetty6適用):
那么其它服務器有沒有類似情況,答案當然是肯定的,如Tomcat,通過搜索找到了如下內容:
Q: In Tomcat, I got a "Post data too big" error.
A: Apache Tomcat by default sets a limit on the maximum size of HTTP POST requests it accepts.
In Tomcat 5, this limit is set to 2097152 (2 Mb). When you try to upload files or post forms that are
larger than 2 MB, this error can occur.
The solution is to reconfigure Tomcat to accept larger POST requests, either by increasing
the limit, or by disabling it. This can be done by editing Tomcat's server.xml.
In the <Connector> element, add an attribute "maxPostSize" and set a larger value (in bytes) to
increase the limit. Setting it to 0 will disable the size check.
意思是說,tomcat默認設置能接收HTTP POST請求的大小最大為2M,如果你的POST請求傳遞的數據大於2M,就會報這個錯誤.解決的辦法是修改tomcat的配置文件$TOMCAT_HOME$/conf/server.xml,找到里面的<Connector>標簽,在該標簽中添加"maxPostSize"屬性,將該屬性值設置成你想要的最大值,單位是字節,如果你把這個值設置為0(maxPostSize="0"),tomcat將不再檢查POST的大小.
本人測試環境如下:
Jetty版本:Run Jetty Run Feature1.2.2.1
Jetty對應的jar包版本:org.mortbay.jetty.server_6.1.23.v201012071420.jar
對於Jetty7只需改下包的路徑,完整配置文件如下: