54
54
public class TestServlet extends HttpServlet {
55
55
56
56
/**
57
- * Processes requests for both HTTP
58
- * <code>GET</code> and
59
- * <code>POST</code> methods.
57
+ * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
58
+ * methods.
60
59
*
61
60
* @param request servlet request
62
61
* @param response servlet response
@@ -66,42 +65,40 @@ public class TestServlet extends HttpServlet {
66
65
protected void processRequest (HttpServletRequest request , HttpServletResponse response )
67
66
throws ServletException , IOException {
68
67
response .setContentType ("text/html;charset=UTF-8" );
69
- try (PrintWriter out = response .getWriter ()) {
70
- out .println ("<!DOCTYPE html>" );
71
- out .println ("<html>" );
72
- out .println ("<head>" );
73
- out .println ("<title>Servlet Event Listeners</title>" );
74
- out .println ("</head>" );
75
- out .println ("<body>" );
76
- out .println ("<h1>Servlet Event Listeners</h1>" );
77
- out .println ("<h2>Setting, updating, and removing ServletContext Attributes</h2>" );
78
- request .getServletContext ().setAttribute ("attribute1" , "attribute-value1" );
79
- request .getServletContext ().setAttribute ("attribute1" , "attribute-updated-value1" );
80
- request .getServletContext ().removeAttribute ("attribute1" );
81
- out .println ("done" );
82
- out .println ("<h2>Setting, updating, and removing HttpSession Attributes</h2>" );
83
- request .getSession (true ).setAttribute ("attribute1" , "attribute-value1" );
84
- request .getSession ().setAttribute ("attribute1" , "attribute-updated-value1" );
85
- request .getSession ().removeAttribute ("attribute1" );
86
- out .println ("done" );
87
- out .println ("<h2>Setting, updating, and removing ServletRequest Attributes</h2>" );
88
- request .setAttribute ("attribute1" , "attribute-value1" );
89
- request .setAttribute ("attribute1" , "attribute-updated-value1" );
90
- request .removeAttribute ("attribute1" );
91
- out .println ("done" );
92
- out .println ("<h2>Invalidating session</h2>" );
93
- request .getSession ().invalidate ();
94
- out .println ("done" );
95
- out .println ("<br><br>Check output in server log" );
96
- out .println ("</body>" );
97
- out .println ("</html>" );
98
- }
68
+ PrintWriter out = response .getWriter ();
69
+ out .println ("<!DOCTYPE html>" );
70
+ out .println ("<html>" );
71
+ out .println ("<head>" );
72
+ out .println ("<title>Servlet Event Listeners</title>" );
73
+ out .println ("</head>" );
74
+ out .println ("<body>" );
75
+ out .println ("<h1>Servlet Event Listeners</h1>" );
76
+ out .println ("<h2>Setting, updating, and removing ServletContext Attributes</h2>" );
77
+ request .getServletContext ().setAttribute ("attribute1" , "attribute-value1" );
78
+ request .getServletContext ().setAttribute ("attribute1" , "attribute-updated-value1" );
79
+ request .getServletContext ().removeAttribute ("attribute1" );
80
+ out .println ("done" );
81
+ out .println ("<h2>Setting, updating, and removing HttpSession Attributes</h2>" );
82
+ request .getSession (true ).setAttribute ("attribute1" , "attribute-value1" );
83
+ request .getSession ().setAttribute ("attribute1" , "attribute-updated-value1" );
84
+ request .getSession ().removeAttribute ("attribute1" );
85
+ out .println ("done" );
86
+ out .println ("<h2>Setting, updating, and removing ServletRequest Attributes</h2>" );
87
+ request .setAttribute ("attribute1" , "attribute-value1" );
88
+ request .setAttribute ("attribute1" , "attribute-updated-value1" );
89
+ request .removeAttribute ("attribute1" );
90
+ out .println ("done" );
91
+ out .println ("<h2>Invalidating session</h2>" );
92
+ request .getSession ().invalidate ();
93
+ out .println ("done" );
94
+ out .println ("<br><br>Check output in server log" );
95
+ out .println ("</body>" );
96
+ out .println ("</html>" );
99
97
}
100
98
101
99
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
102
100
/**
103
- * Handles the HTTP
104
- * <code>GET</code> method.
101
+ * Handles the HTTP <code>GET</code> method.
105
102
*
106
103
* @param request servlet request
107
104
* @param response servlet response
@@ -115,8 +112,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
115
112
}
116
113
117
114
/**
118
- * Handles the HTTP
119
- * <code>POST</code> method.
115
+ * Handles the HTTP <code>POST</code> method.
120
116
*
121
117
* @param request servlet request
122
118
* @param response servlet response
0 commit comments