'HTML content is lost when printing from JSP
I am making software to print information into a JSP file. I have a list of objects with a size of 50. However, when I'm looping through the list and printing the content into HTML format, only around 20 objects were printed. How can I print all the information of all 50 objects into a single HTML webpage? Below is my code, thank you for your help!
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
String query = request.getParameter("query");
QueryResScore results = Retrieval.doQuery(query);
//output.size() == 50 but only around 20 were printed
List<ForwardData> output = results.getResults();
List<String> queryWordList = results.getQuery();
List<Double> scores = results.getScores();
DecimalFormat df = new DecimalFormat("#.###");
try (PrintWriter writer = response.getWriter()) {
writer.println("<!DOCTYPE html><html>");
writer.println("<head>");
writer.println("<meta charset=\"UTF-8\" />");
writer.println("<title>Sample Application Servlet Page</title>");
writer.println("</head>");
writer.println("<body style='padding-left: 30px; padding-right: 30px'>");
writer.println("<div style=\"float: left; padding: 10px;\">");
writer.println("<img src=\"images/tomcat.gif\" alt=\"\" />");
writer.println("</div>");
writer.println("<h1>Results</h1>");
writer.println("<h3>Results retrieved: " + output.size() + "</h3>");
// writer.println("</p>");
writer.println("<table style='width: 600px'>");
for (int curRes = 0; curRes < output.size(); curRes++) {
ForwardData result = output.get(curRes);
writer.println("<tr>");
writer.println("<td style='vertical-align: top; width: 100px'>");
writer.println("Score: " + df.format(scores.get(curRes)));
writer.println("</td>");
writer.println("<td style='vertical-align: top'>");
writer.print("<a style='font-size:25px;text-decoration:none;' href='" + result.url + "'>");
writer.print(result.wordTitle);
writer.println("</a>");
writer.println("<br>");
writer.print("<a href='" + result.url + "'>");
writer.print(result.url);
writer.println("</a>");
writer.println("<br>");
// writer.print("No last modified date");
if (result.lastModified.replaceAll("\\s+", "").equals("")) {
writer.print("No last modified date");
} else {
writer.print(result.lastModified);
}
writer.print("; ");
writer.print(result.size + " characters");
List<WordData> keyWordListTitle = getKeyWordList(result.title, queryWordList);
if (keyWordListTitle.size() > 0) {
writer.println("<br>");
writer.println("Title Matches: <br>");
}
for (WordData keyWord : keyWordListTitle) {
writer.print(keyWord.data + " " + keyWord.count + "; ");
}
List<WordData> keyWordList = getKeyWordList(result.content, queryWordList);
if (keyWordList.size() > 0) {
writer.println("<br>");
writer.println("Content Matches: <br>");
}
for (WordData keyWord : keyWordList) {
writer.print(keyWord.data + " " + keyWord.count + "; ");
}
if (keyWordList.size() == 0 && keyWordListTitle.size() == 0) {
writer.print("No Keyword Matched <br>");
}
writer.println("<br>");
int maxLink = 10;
int curLink = 0;
writer.println("Parent Links:<br>");
for (String link : result.parentLink) {
curLink++;
writer.print("<a href='" + link + "'>");
writer.print(link);
writer.println("</a>");
writer.println("<br>");
if (curLink >= maxLink)
break;
}
curLink = 0;
writer.println("Children Links:<br>");
for (String link : result.childrenLink) {
curLink++;
writer.print("<a href='" + link + "'>");
writer.print(link);
writer.println("</a>");
writer.println("<br>");
if (curLink >= maxLink)
break;
}
writer.println("<br>");
writer.println("</td>");
writer.println("</tr>");
}
writer.println("</table>");
writer.println("</body>");
writer.println("</html>");
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|