import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
* Prints the ELOI staff.
*
* @author Sofoklis Stouraitis
*/
public class ViewStaff extends HttpServlet {
/**
* Handles HTTP POST requests.
*
* @param request
* the request object
* @param response
* the response object
*
* @throws IOException
* if an input or output error is detected when the servlet
* handles the POST request.
* @throws ServletException
* if the request for the POST could not be handled.
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html; charset=ISO-8859-7");
PrintWriter out = new PrintWriter(response.getWriter(), true);
ResultSet rs1 = null;
try {
/*
* Initialize EloiStaff Object in order to connect to the database.
*/
EloiStaff eloi = new EloiStaff();
/*
* Establish connection with database.
*/
eloi.open();
/*
* Executes query and gets the results.
*/
rs1 = eloi.getEloiStaff();
out.println("<html>");
out.println("<head>");
out.println("<Meta Http-Equiv='Content-Type' Content='text/html; Charset=iso-8859-7'>");
out.println("<title>Προσωπικό Εκπαιδευτικού Εργαστηρίου Πληροφορικής</title>");
out.println("</head>");
out.println("<body>");
out.println("<br>");
if (rs1 == null) {
/*
* Prints the error.
*/
out.println("<b>Database Error:</b><br>" + eloi.getErrorMessages());
/*
* ends the connection with database
*/
eloi.close();
out.println("</body>");
out.println("</html>");
return;
}
out.println("<div align='center'><table border='1' width='60%'>");
out.println("<tr>");
out.println("<td width='11%' bgcolor='#C0C0C0'>");
out.println("<p align='center'><b><font color='#000080'>A.M :</font></b></td>");
out.println("<td width='39%' bgcolor='#C0C0C0'>");
out.println("<p align='center'><b><font color='#000080'>SURNAME :</font></b></td>");
out.println("<td width='44%' bgcolor='#C0C0C0'>");
out.println("<p align='center'><b><font color='#000080'>NAME :</font></b></td>");
out.println("<td width='6%' bgcolor='#C0C0C0'>"
+ "<b><font color='#000080'>R.N :</font></b></td>");
out.println("</tr>");
// variable counter will help us to determine if the query returned any results or not.
int counter = 0;
while (rs1.next()) {
String am = rs1.getString("AM");
String surname = rs1.getString("SURNAME");
String name = rs1.getString("NAME");
int idNumber = rs1.getInt("ID");
out.println("<tr>");
out.println("<td width='11%' align='center'>" + am + "</td>");
out.println("<td width='39%' align='center'>" + surname + "</td>");
out.println("<td width='44%' align='center'>" + name + "</td>");
out.println("<td width='6%' align='center'>" + idNumber + "</td>");
out.println("</tr>");
counter++;
}
if(counter == 0) {
out.println("<tr>");
out.println("<td colspan='4'><div align='center'>No results found!</div></td>");
out.println("</tr>");
}
out.println("</table></div>");
out.println("</body>");
out.println("</html>");
/*
* ends the connection with database
*/
eloi.close();
} catch (Exception e) {
/*
* Prints the error.
*/
out.println("<br><b>Error:</b> " + e.getMessage());
out.println("</body>");
out.println("</html>");
}
}
}//end of class
|