You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Log.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.util.logging.Level;
  9. import java.util.logging.Logger;
  10. import javax.servlet.ServletException;
  11. import javax.servlet.annotation.WebServlet;
  12. import javax.servlet.http.HttpServlet;
  13. import javax.servlet.http.HttpServletRequest;
  14. import javax.servlet.http.HttpServletResponse;
  15. /**
  16. *
  17. * @author Edi
  18. */
  19. @WebServlet(urlPatterns = {"/Log"})
  20. public class Log extends HttpServlet {
  21. /**
  22. * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  23. * methods.
  24. *
  25. * @param request servlet request
  26. * @param response servlet response
  27. * @throws ServletException if a servlet-specific error occurs
  28. * @throws IOException if an I/O error occurs
  29. */
  30. String context = "";
  31. public void init() {
  32. }
  33. protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  34. throws ServletException, IOException, Exception {
  35. try (PrintWriter out = response.getWriter()) {
  36. /* TODO output your page here. You may use following sample code. */
  37. if(request.getParameter("log") != null) {
  38. context = context + "\n" + request.getParameter("log");
  39. }
  40. out.println(context);
  41. }
  42. }
  43. // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  44. /**
  45. * Handles the HTTP <code>GET</code> method.
  46. *
  47. * @param request servlet request
  48. * @param response servlet response
  49. * @throws ServletException if a servlet-specific error occurs
  50. * @throws IOException if an I/O error occurs
  51. */
  52. @Override
  53. protected void doGet(HttpServletRequest request, HttpServletResponse response)
  54. throws ServletException, IOException {
  55. response.setIntHeader("Refresh", 2);
  56. try {
  57. processRequest(request, response);
  58. } catch (Exception ex) {
  59. Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
  60. }
  61. }
  62. /**
  63. * Handles the HTTP <code>POST</code> method.
  64. *
  65. * @param request servlet request
  66. * @param response servlet response
  67. * @throws ServletException if a servlet-specific error occurs
  68. * @throws IOException if an I/O error occurs
  69. */
  70. @Override
  71. protected void doPost(HttpServletRequest request, HttpServletResponse response)
  72. throws ServletException, IOException {
  73. response.setIntHeader("Refresh", 2);
  74. try {
  75. processRequest(request, response);
  76. } catch (Exception ex) {
  77. Logger.getLogger(Logic.class.getName()).log(Level.SEVERE, null, ex);
  78. }
  79. }
  80. /**
  81. * Returns a short description of the servlet.
  82. *
  83. * @return a String containing servlet description
  84. */
  85. @Override
  86. public String getServletInfo() {
  87. return "Short description";
  88. }// </editor-fold>
  89. }