viewResults.jsp
<%--
/**
 * Gets and Prints records from the database.
 *
 @author Sofoklis Stouraitis
 */
--%>

<%--   Set content type --%>
<%page contentType="text/html; charset=Windows-1253" %>

<%--   Import necessary libs (java.sql.*--%>
<%page import="java.sql.*" %>

<%--   Define error page.
  Redirect to "applicationErrorPage.jsp" if encounter an error --%>
<%page errorPage="applicationErrorPage.jsp" %>


<html>
  <head>
    <title>1ο Παράδειγμα JSP - viewResults.jsp</title>
    <meta http-equiv="Content-Type" content="text/html; charset=Windows-1253">
  </head>
  <body>

<%--   We need this line in order to pass parameters in greek, we can use UTF-charset as well.
  Try to comment out ("//"this line to see the difference.
--%>    
<% request.setCharacterEncoding("ISO-8859-7"); %>
        
<%--   Include page "header.jsp" passing the parameter "exampleNumber" --%>
<jsp:include page="header.jsp"
  <jsp:param name="exampleNumber" value="1ο Παράδειγμα" /> 
</jsp:include>    
    
  <div style="height:500px;text-align:center;">
        <h1><font color="#000066"><strong>"viewResults.jsp" is running...</strong></font></h1>
        <br />

<%--   Gets the results from the request and store them in a ResultSet --%>
<% ResultSet rs = (ResultSet)request.getAttribute("records"); %>

        <table border="1" width="60%" align="center">
    <tr>
      <td width="11%" bgcolor="#C0C0C0">
        <p align="center"><b><font color="#000080">A.M&nbsp;:</font></b>
      </td>
      <td width="39%" bgcolor="#C0C0C0">
        <p align="center"><b><font color="#000080">SURNAME&nbsp;:</font></b>
      </td>
      <td width="44%" bgcolor="#C0C0C0">
        <p align="center"><b><font color="#000080">NAME&nbsp;:</font></b>
      </td>
      <td width="6%" bgcolor="#C0C0C0">
        <b><font color="#000080">R.N&nbsp;:</font></b>
      </td>
    </tr>
    
<%--   Retrieves records from the ResultSet --%>
<%
while (rs.next()) {
  String am = rs.getString("AM");
  String surname = rs.getString("SURNAME");
  String name = rs.getString("NAME");
  int idNumber = rs.getInt("ID");
%>  
    <tr>    
      <%-- Prints am (see the use "<%="--%>
      <td width="11%" align="center"><%= am %></td>
    
      <%-- Prints surname --%>
      <td width="39%" align="center"> <%= surname %> </td>
    
      <%-- Prints name --%>
      <td width="44%" align="center"> <%= name %>   </td>
    
      <%-- Prints idNumber --%>
      <td width="6%" align="center">  <%= idNumber %>  </td>
    </tr>
<%    
//and of while

/*
 * Moves the cursor to the first row in ResultSet.
 * first() returns true if the cursor is on a valid row; false if there are no rows in the result set (that means that no records found). 
 *  
*/
if(!rs.first()) {          
  // use out.println to see an alternative way to print directly from a jsp.
  out.println("<td colspan='4' align='center'>No records found!</td>");
}
%>      
    </table>        
  </div>    
    
<%--    Include the page "footer.html"  --%>    
<jsp:include page="footer.html" />    
    
  </body>
</html>