⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpsessioninspector.java

📁 噶额外噶外骨骼感广泛高热感 就 啊啊
💻 JAVA
字号:
package itso.basicweb.listener;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

/**
 * @version 	1.0
 * @author
 */
public class HttpSessionInspector
	implements HttpSessionListener, HttpSessionAttributeListener {

	/**
	* @see javax.servlet.http.HttpSessionAttributeListener#void (javax.servlet.http.HttpSessionBindingEvent)
	*/
	public void attributeRemoved(HttpSessionBindingEvent arg0) {
		report ("Attribute " + arg0.getName() + " removed", arg0.getSession(), arg0.getValue());
	}

	/**
	* @see javax.servlet.http.HttpSessionListener#void (javax.servlet.http.HttpSessionEvent)
	*/
	public void sessionDestroyed(HttpSessionEvent arg0) {
		report ("Session destroyed", arg0.getSession(), null); 
	}

	/**
	* @see javax.servlet.http.HttpSessionAttributeListener#void (javax.servlet.http.HttpSessionBindingEvent)
	*/
	public void attributeAdded(HttpSessionBindingEvent arg0) {
		report ("Attribute " + arg0.getName() + " added", arg0.getSession(), arg0.getValue());
	}

	/**
	* @see javax.servlet.http.HttpSessionAttributeListener#void (javax.servlet.http.HttpSessionBindingEvent)
	*/
	public void attributeReplaced(HttpSessionBindingEvent arg0) {
		report ("Attribute " + arg0.getName() + " replaced", arg0.getSession(), arg0.getValue());
	}

	/**
	* @see javax.servlet.http.HttpSessionListener#void (javax.servlet.http.HttpSessionEvent)
	*/
	public void sessionCreated(HttpSessionEvent arg0) {
		report ("Session created", arg0.getSession(), null); 
	}

	// helper methods
	private int size (Object anObject) {
		ByteArrayOutputStream array = new ByteArrayOutputStream ();
		try {
			(new ObjectOutputStream (array)).writeObject(anObject);
			return array.size();
		} catch (IOException e) {
			return -1;
		}
	}

	private void report (String reason, HttpSession session, Object value) {
		if (value == null) 
			System.out.println (reason + ": session #" + session.hashCode() + " size: " + size(session));
		else
			System.out.println (reason + ": session #" + session.hashCode() + " size: " + size(session) +
					" Attribute size: " + size(value));
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -