EmailToPhone Log Servlet | Email To Phone Code Review
This is the Servlet class to display the EmailToPhone log file.
EmailManager mgr = EmailManager.instance_;
String appdir = getServletContext().getRealPath("..");
File f = new File(appdir + "/email.log");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String line;
while ((line = br.readLine()) != null)
w.println(line);
br.close();
fr.close();
The log file is saved as email.log.
Source Code
public class LogFileServlet extends HttpServlet
{
public void service(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
PrintWriter w = response.getWriter();
w.println("<html>");
w.println("<head>");
w.println("<meta http-equiv=\"Content-Language\" content=\"en-us\">");
w.println("<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=windows-1252\">");
w.println("<title>EmailToPhone - Log File</title>");
w.println("</head>");
w.println("<body>");
w.println("<pre>");
String appdir = getServletContext().getRealPath("..");
File f = new File(appdir + "/email.log");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
String line;
while ((line = br.readLine()) != null)
w.println(line);
br.close();
fr.close();
w.println("</pre>");
w.println("</body>");
w.println("</html>");
}
}