我正在尝试向用户显示页面加载时的列表。 当页面加载时我做了,AJAX调用数据库并返回DTO列表。在控制器中,我将DTO列表设置到模型中,在JSP页面上,我尝试通过JSTL循环访问列表值。
这是我的代码
ajax - >
$(document).ready(function() {
$.ajax({
url : 'loadInterests',
dataType : "json",
type : "GET",
success: function (response)
{
}
,
error: function (response)
{
}
});
});
contoller - >
@RequestMapping(value="/loadInterests", method = RequestMethod.GET)
public List<InterestsDto> loadInterests( Model model1)
{
String Email = ((UserDetailsDto)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername();
long id = ((UserDetailsDto)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId();
System.out.println(" " +Email+ " kkk " +id);
List<InterestsDto> interests = userService.loadInterests(Email ,id);
System.out.println("controller out ");
for(int i =0 ; i < interests.size(); i++)
{
System.out.println( "id == " +interests.get(i).getName());
System.out.println( "value == " +interests.get(i).getId());
}
model1.addAttribute("interests", interests);
return interests;
}
jsp - &gt;
<div class="talentBoxMain">
<c:forEach var="i" begin="0" end="${interests.size()}" items="${interests}">
<br>
<div class="talentBox10 addTalentBox">
<div class="media"> <a href="#" class="pull-left">
<img alt="..." src="resources/img/talent-singing.jpg" class="media-object img-rounded"></a>
<div class="media-body">
<h5 class="pull-left"><a href="#"><c:out value="${i}"/>${i.getName()}</a></h5>
<a class="btn btn-info btn-sm pull-right addBtn" href="#"><span class="glyphicon glyphicon-plus"></span> Add</a> </div>
</div>
</div>
</c:forEach>
代码不起作用。每次我尝试加载页面时都会抛出NullPointerException类型的异常。
java.io.IOException:评估正文时的JspException
请帮忙。