在我的web应用程序我生成ID动态内容。下面我code
In my web app I generate dynamic content for id. Below my code
function lookup(){
<% List<UserOrganization> el = (List<UserOrganization>) request.getAttribute("uselist");%>
<% for (int i = 0; i < el.size(); i++) {%>
var email<%out.print(i);%>="<%out.print(el.get(i).getUser_1().getEmailId());%>";
$.ajax({
type: "POST",
url: "EveConnectOutletsCount",
data: {
email:email<%out.print(i);%>
},
success: function(data) {
$('#ec<%out.print(i);%>').html(data)
}
});
<% }%>
}
JSP页面:
<s:iterator value="uselist">
<span id="ec<%=n%>"></span>
</s:iterator>
本页面执行罚款,如果 uselist
有一定价值。它抛出500错误code。如果 uselist
是空的。
我怎样才能避免这个错误?
This page executes fine, if uselist
has some value. It throws 500 error code if uselist
is empty.
How can I avoid this error?
我通过增加低于code解决了这个问题。
I solved the problem by adding below code.
function lookup() {
'<s:if test="uselist.size()>0">'
<% List<UserOrganization> el = (List<UserOrganization>) request.getAttribute("uselist");%>
<% for (int i = 0; i < el.size(); i++) {%>
var email<%out.print(i);%>="<%out.print(el.get(i).getUser_1().getEmailId());%>";
$.ajax({
type: "POST",
url: "EveConnectOutletsCount",
data: {
email:email<%out.print(i);%>
},
success: function(data) {
$('#ec<%out.print(i);%>').html(data)
}
});
<% }%>
'</s:if>'
}
因此,如果列表空
,我的code不会产生空指针异常。
so if list is null
, my code wont generates null pointer exception.