Two listening notes for Jsp listening requests

Source: Internet
Author: User

By implementing the following listener, we can listen to the detailed information of each request of this application and record it as a log. Below I will introduce the implementation process of the two listeners of the specific Jsp listener request.

The following class implements two interfaces, so that this class can have multiple functions (Listening for changes to attributes in the request and request range)

1. compile our class

The Code is as follows: Copy code

Package org. Rudiment. Listener;

Import javax. servlet. ServletRequestAttributeEvent;
Import javax. servlet. ServletRequestAttributeListener;
Import javax. servlet. ServletRequestEvent;
Import javax. servlet. ServletRequestListener;
Import javax. servlet. http. HttpServletRequest;

Public class MyRequestListener implements ServletRequestListener, ServletRequestAttributeListener
{

@ Override
Public void attributeAdded (ServletRequestAttributeEvent arg0 ){
System. out. println ("attribute in the Request range:" + arg0.getName () + "added, value:" + arg0.getValue ());
}

@ Override
Public void attributeRemoved (ServletRequestAttributeEvent arg0 ){
System. out. println ("attribute in the Request range:" + arg0.getName () + "deleted, value:" + arg0.getValue ());
}

@ Override
Public void attributeReplaced (ServletRequestAttributeEvent arg0 ){
System. out. println ("attribute in the Request range:" + arg0.getName () + "value updated to:" + arg0.getValue ());
}

@ Override
Public void requestDestroyed (ServletRequestEvent arg0 ){
HttpServletRequest request = (HttpServletRequest) arg0.getServletRequest ();
System. out. println ("the request is about to end ");
}

@ Override
Public void requestInitialized (ServletRequestEvent arg0 ){
HttpServletRequest request = (HttpServletRequest) arg0.getServletRequest ();
System. out. println ("the request is about to begin. The request comes from" + request. getHeader ("Referer") + "send" + request. getRequestURI ());
}

}

2. configure our listener in web. xml

The Code is as follows: Copy code

<Listener>
<Listener-class> org. Rudiment. Listener. MyRequestListener </listener-class>
</Listener>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.