Tomcat上java.lang.IllegalStateException: Optional int parameter 'id' is not present

來源:互聯網
上載者:User

標籤:

今日, 本人在tomcat+spring mvc平台的伺服器上遇到java.lang.IllegalStateException: Optional int parameter ‘id‘ is not present異常, 很是怪異, mvc方法裡面的id為int型, 明明是有值的, 為什麼說沒有? 改為Integer也不行, mvc方法直接無響應!

 

然後, 在本地類比改用例, 發現可以正常執行, 而另一個同事說要把超長的圖片參數放到Mvc方法的最後就可以正常訪問! 怪異!

後來經過多次實驗, 發現是其他參數的長度很長很長,例如存放圖片的base64, 可能會超出tomcat的預設的post最多長度(2M), 但是網上很多人說超長拋出的異常應該是"post too large", 但是卻拋出了另一種異常: :java.lang.IllegalStateException: Optional int parameter ‘id‘ is not prese nt but cannot be translated into a null value due to being declared as a primiti ve type. Consider declaring it as object wrapper for the corresponding primitive  type.

 

本人的理解是sping mvc忽略了post too large異常, 直接對請求參數內容進行截取, 導致了id參數為空白, 因此才出現了這樣怪異的現象. 

 

解決的辦法當然就是在tomcat的server.xml裡面加一個maxPostSize="0"

Tomcat上java.lang.IllegalStateException: Optional int parameter 'id' is not present

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.