[英]servlet request.getParameterValues(fieldName) returns null and throw exception
[英]Request.getParameterValues returns null when not in IE5 quirks mode
我有一個jsp頁面,該頁面始終將20個項目的列表發送回我的Java控制器。 基本上,我有一個id值,該值會增加,但會分配給20個同名項目。
jsp:
<input type="text" style="display: none" name="displayId" id="<%=displayId%>" value="<%=displayId%>">
我在上面設置顯示ID的位置。 然后,在提交頁面后的后端,我將此代碼稱為抓取項目。
String[] displayIds = request.getParameterValues("displayId");
for (String i: displayIds)
{ ...do some other stuff
我的問題是提交頁面后,displayIds數組為null。 我想離開IE5的怪癖模式,以便該頁面可以在其他瀏覽器上運行。 我還有其他更“標准”的方式可以做到這一點嗎?
好的,看來我的問題與jsp頁面的設置有關。 頁面上有2個嵌套表單,看起來最初的設計是先提交它,然后從request.getParameterValues()中獲取ID。我能夠采用外部表單並將其移動,以便標記正確對齊然后使用for循環遍歷值(具有dispalyIds的for循環只是在請求值的末尾添加一個遞增整數),然后在for循環內使用request.getParameter(“ name” + i)來獲取值我需要。
然后,我不再有任何空值,並且可以保存。 希望這可以幫助某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.