tailieunhanh - Teach Yourself J2EE in 21 Days phần 6

Triển khai ứng dụng. Bây giờ, mỗi khi HTMLPage được truy cập, truy cập sẽ được tăng lên và đăng nhập. Các file bản ghi sẽ được tìm thấy trong thư mục cài đặt J2EE của bạn theo các bản ghi name | 540 Day 12 4. Now map the filter to the page whose access you want to be logged. In this case HTMLPage see Figure . Figure deploytool Filter Mapping. The following deployment descriptor entry shows the AuditFilter mapped to the HTMLPage filter-mapping filter-name AuditFilter filter-name servlet-name HTMLPage servlet-name filter-mapping 5. Deploy the application. Now every time the HTMLPage is accessed the counter will be incremented and logged. The log file will be found in your J2EE installation directory under logs machine name web. There will probably be a number of log files in this directory look for the one with the latest date on it. At the end of the log file you should see something like the following HTMLPage init The number of hits is 1 The number of hits is 2 The number of . Servlets 541 Another way to see if the filter is working is to amend the HTMLPage code to output the counter as shown in Listing . Listing HTMLPage with Counter Added 1 import . 2 import . 3 import . 4 5 public class HTMLPage extends HttpServlet 6 7 public void doGet HttpServletRequest req HttpServletResponse res 8 throws ServletException lOException 9 image gif 10 Printwriter out 11 HTML 12 HEAD TlTLE Filtered Servlet TITLE HEAD 13 BODY 14 H1 A Generated HTML Page with a Filter attached H1 15 Integer counter Integer getServletContext .getAttribute Counter 16 P This page has been accessed 1 1 counter 1 1 times P 17 BODY 18 HTML 19 20 This was a very simple example more sophisticated filters can be used to modify the request or the response. To do this you must override the request or response methods by wrapping the request or response in an object that extends HttpServletRequestWrapper or HttpServletResponseWrapper. This approach follows the well-known Wrapper or Decorator pattern technique. Patters will be

TÀI LIỆU MỚI ĐĂNG
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.