I have large amounts of data in an ArrayList that holds about 2,600 classes from my College. I am trying to build them a JSP page that will display this information. I am having trouble figuring out how to approach displaying this data in a table.
To test out in the beginning, I did this just to verify I could access the data.
HTML:
<html>
<head>
<body>
<button id="btnData">Get all classes.</button>
<div id="dataDisp></div>
<script>
$(document).ready(function(){
$("#btnData).click(function(){
$.get('daoServlet', function(responseText){
$("#dataDisp").text(responseText);
});
});
});
</body>
<html>
Servlet:
@WebServlet("/daoServlet/*")
public class ClassDAO extends HttpServlet
{
//Code getting my ArrayList<ClassInfo> set up, etc.
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String text = fallClassListings.toString();
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(text);
}
}
This will display every single class. So, what direction could I take to format this data into a table in my index.jsp page? I tried doing something like
text = "<h1>This is an h1 tag</h1>";
Just to see if I could return some HTML, but that just prints out the whole string literal, not an h1 tag.
Any help is appreciated!
The only problem that I see with your implementation in jquery is having “.text()”. Instead, replace it with “.html()” of the “div” as shown below.
Also, you could have a for loop on the list and build the table with “tr”s and “td”s in the Index.jsp file and return the same to jquery.
Hope this Helps!!