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("Request範圍中的屬性:" + arg0.getName() + " 被添加,數值為:" + arg0.getValue()); } @Override public void attributeRemoved(ServletRequestAttributeEvent arg0) { System.out.println("Request範圍中的屬性:" + arg0.getName() + " 被刪除,數值為:" + arg0.getValue()); } @Override public void attributeReplaced(ServletRequestAttributeEvent arg0) { System.out.println("Request範圍中的屬性:" + arg0.getName() + " 數值更新為:" + arg0.getValue()); } @Override public void requestDestroyed(ServletRequestEvent arg0) { HttpServletRequest request = (HttpServletRequest)arg0.getServletRequest(); System.out.println("請求即將結束" ); } @Override public void requestInitialized(ServletRequestEvent arg0) { HttpServletRequest request = (HttpServletRequest)arg0.getServletRequest(); System.out.println("請求即將開始,請求來自" + request.getHeader("Referer") + "發向" + request.getRequestURI()); } } |