/**
* 获取HttpSession缓存大小
* @param session HttpSession
* @param filePath 输入文件
*/
public static void getSessionSize(HttpSession session, String filePath)
{
FileOutputStream fileOutputStream = null;
ObjectOutputStream objectOutputStream = null;
try
{
fileOutputStream = new FileOutputStream(filePath);
objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject("session:");
Enumeration<String> names = session.getAttributeNames();
while (names.hasMoreElements())
{
objectOutputStream.writeObject(session.getAttribute(names.nextElement()));
}
objectOutputStream.flush();
}
catch (Exception e)
{
e.printStackTrace();
try
{
if (null != objectOutputStream)
{
objectOutputStream.close();
}
}
catch (IOException e1)
{
System.out.println(e1.toString());
}
try
{
if (null != fileOutputStream)
{
fileOutputStream.close();
}
}
catch (IOException e1)
{
System.out.println(e1.toString());
}
}
finally
{
if (null != objectOutputStream)
{
try
{
objectOutputStream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (null != fileOutputStream)
{
try
{
fileOutputStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
* 获取HttpSession缓存大小
* @param session HttpSession
* @param filePath 输入文件
*/
public static void getSessionSize(HttpSession session, String filePath)
{
FileOutputStream fileOutputStream = null;
ObjectOutputStream objectOutputStream = null;
try
{
fileOutputStream = new FileOutputStream(filePath);
objectOutputStream = new ObjectOutputStream(fileOutputStream);
objectOutputStream.writeObject("session:");
Enumeration<String> names = session.getAttributeNames();
while (names.hasMoreElements())
{
objectOutputStream.writeObject(session.getAttribute(names.nextElement()));
}
objectOutputStream.flush();
}
catch (Exception e)
{
e.printStackTrace();
try
{
if (null != objectOutputStream)
{
objectOutputStream.close();
}
}
catch (IOException e1)
{
System.out.println(e1.toString());
}
try
{
if (null != fileOutputStream)
{
fileOutputStream.close();
}
}
catch (IOException e1)
{
System.out.println(e1.toString());
}
}
finally
{
if (null != objectOutputStream)
{
try
{
objectOutputStream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
if (null != fileOutputStream)
{
try
{
fileOutputStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}