Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to disaply list in ajax from spring controller(mvc)  RSS feed

mallikarjun patil
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have developed an application using spring MVC. I am implemeting dashboard in it, which contains recently uploaded documents.
I want to display only 10 documents in a page and rest should come under pagination.
I am getting documents list through controller class, from there i'd like display the documents on a jsp page using Ajax.
But I am not getting how to display the documents(I am not getting response from ajax). Please find the below code and help me out.

in controller

@RequestMapping(value = "/fileList", method = RequestMethod.GET)
public @ResponseBody
List<File> fileList(HttpServletRequest req) {
Subject subject = SecurityUtils.getSubject();
Session session = subject.getSession();
User user1 = (User) session.getAttribute("objUser");
long userSesId = user1.getUserId();
int pageNumber=Integer.parseInt(req.getParameter("pageNo")) ;
List<File>files= dashboardService.listFiles(user1.getRoles().getRoleId(),pageNumber);
return files;


in jsp

<div class="dashboard">
<div class="dashboard_inner">
<div id="draggable1">
<div class="box">Recently Uploaded Documents</div>
<div class="slider">
<img src="../images/collapseminus.gif" />
<div class="internal">

<table cellpadding="0" cellspacing="2"
<th colspan="4"><h6>Recently Uploaded Documents</h6></th>
<tr style="background: #dbebf8;">
<!-- <td width="20px"> </td> -->
<td width="50px" id="center"><span>Type</span></td>
<td width="250px" id="center"><span>Name</span></td>
<td width="150px" id="center"><span>Creation Date</span></td>
<td width="300px" id="center"><span>Author</span></td>


<c:if test="${!empty lists}">
<c:forEach items="${lists}" var="FileList">
<c:when test="${FileList.contentType=='docx'}">
<img src="../images/word.jpg">
<c:when test="${FileList.contentType=='pdf'}">
<img src="../images/pdf.jpg">
<c:when test="${fn:toLowerCase(FileList.contentType)=='jpg'}">
<img src="../images/image.jpg">
<c:when test="${fn:toLowerCase(FileList.contentType)=='gif'}">
<img src="../images/image.jpg">
<c:when test="${fn:toLowerCase(FileList.contentType)=='png'}">
<img src="../images/image.jpg">
<c:when test="${fn:toLowerCase(FileList.contentType)=='bmp'}">
<img src="../images/image.jpg">
<c:when test="${FileList.contentType=='xlsx'}">
<img src="../images/xls.jpg">
<c:when test="${FileList.contentType=='xml'}">
<img src="../images/xml.jpg">
<img src="../images/others.png">
<c:set var="string" value="${FileList.creationDate}" />
<c:set var="start" value=" " />
<c:set var="subCreationDate"
value="${fn:substringBefore(string,start)}" />
<cut value="${FileList.fileName}"></cut> <sup
style="color: #ff0080;">New</sup>
<td id="center"><cut value="${subCreationDate}"></cut></td>
<td><cut value="${FileList.createdUser.userName}"></cut></td>
<c:if test="${empty lists}">
<h4 class="displayMessagePosition">
<cut value="There are no files to display.."></cut>
<c:if test="${!empty pageNosList}">
<c:forEach items="${pageNosList}" var="pageNo">

<INPUT TYPE=BUTTON onclick="updateContent('${pageNo}')">${pageNo}



in ajax

<script type="text/javascript">
var xmlHttp = null;
function updateContent(pageNo) {

try { // Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) { // Internet Explorer

try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {

try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser does not support AJAX!");
return false;

xmlHttp.onreadystatechange = function() {


+ pageNo, true);


function populateActivitiesPno(pageNo) {
if (xmlHttp.readyState == 4) {
var lists = document.getElementById('draggable1');
var response = xmlHttp.responseText;
if (response.length > 0) {
lists = response;
} else {
lists = '';
document.getElementById('draggable1').value = lists;


thanks in advance
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!