import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* This Servlet holds and prints the ip addresses of all visitors.
*
* @author Sofoklis Stouraitis
*
*/
public class LogVisitorsIPServlet extends HttpServlet {
/*
* The String who holds all the ip addresses.
*/
private String visitorsLogger = "";
/**
* Handles HTTP GET 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 GET request
* @throws ServletException
* if the request for the GET 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);
try {
String visitorsIPAddress = request.getRemoteAddr();
visitorsLogger += visitorsIPAddress + "<br>";
out.println("<html>");
out.println("<head>");
out.println(" <title>LogVisitorsIPServlet</title>");
out.println(" <meta http-equiv='Content-Type' content='text/html; charset=windows-1253'>");
out.println("</head>");
out.println(" <bodybgcolor='#FFFF99'>");
out.println(" <h1>LogVisitorsIPServlet is running...</h1><br>");
out.println("<b>Έχουν καταγραφεί τα παρακάτω IP:</b><br>");
out.println("<hr>" + visitorsLogger + "<hr>");
out.println("</body>");
out.println("</html>");
} catch (Exception ex) {
out.println("Exception: " + ex.getMessage());
out.println(" </body>");
out.println("</html>");
}
}
}// End of class
|