毛病信息以下:
代码以下:
<div class="news"> <% ArrayList<JSONObject> list = (ArrayList<JSONObject>)request.getAttribute("newsList"); for(JSONObject j: list){ %> <a href="<%=j.get("url").toString()%>"><%=j.get("title").toString()%></a> <p><%=j.get("postdate")+" "+j.get("content").toString().substring(0,100)%>...</p> <% } %> </div>
依据毛病提醒我发明题目出在这行代码上:
ArrayList<JSONObject> list = (ArrayList<JSONObject>)request.getAttribute("newsList");
直观看上去并没有毛病,request.getAttribute(“newsList”)中的参数名也没有写错,
响应的servlet中也读取到了数据库中的内容,
那为何为报500毛病呢?
代码修正以下:
<div class="news"> <% ArrayList<JSONObject> list = (ArrayList<JSONObject>)request.getAttribute("newsList"); if (list != null && list.size()!=0){ for(JSONObject j: list){ %> <a href="<%=j.get("url").toString()%>"><%=j.get("title").toString()%></a> <p><%=j.get("postdate")+" "+j.get("content").toString().substring(0,100)%>...</p> <% } } %> </div>
即在直接遍历打印list之间,举行非空推断!!!
这也给我今后写代码供应了很大的启发,
在代码范例、代码习气和代码严谨性方面另有很长的路要走!!!
以上就是jsp中500是什么毛病的细致内容,更多请关注ki4网别的相干文章!