httpsessionimpl.java
来自「一个简单的visio程序。」· Java 代码 · 共 204 行
JAVA
204 行
package servlet.http;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.servlet.http.*;
// Referenced classes of package servlet.http:
// SessionContextImpl
public class HttpSessionImpl
implements HttpSession
{
public HttpSessionImpl(SessionContextImpl sessioncontextimpl, Cookie cookie1)
{
sessionObjects = new Hashtable();
creationTime = System.currentTimeMillis();
lastAccessedTime = creationTime;
sc = sessioncontextimpl;
cookieSupportDetermined = false;
cookie = cookie1;
sessionID = sessioncontextimpl.setSession(this);
cookie1.setValue(sessionID);
isNew = true;
isValid = true;
}
public void setNew(boolean flag)
{
isNew = flag;
}
public void setCookieSupported(boolean flag)
{
cookieSupportDetermined = true;
usingCookies = flag;
}
public void setLastAccessedTime()
{
lastAccessedTime = System.currentTimeMillis();
}
public Cookie getCookie()
{
return cookie;
}
public boolean isCookieSupportDetermined()
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
else
return cookieSupportDetermined;
}
public boolean isUsingCookies()
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
else
return true;
}
public boolean isNew()
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
else
return isNew;
}
public boolean isUsingUrlRewriting()
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
else
return false;
}
public String getId()
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
else
return sessionID;
}
public HttpSessionContext getSessionContext()
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
else
return sc;
}
public long getCreationTime()
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
else
return creationTime;
}
public long getLastAccessedTime()
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
else
return lastAccessedTime;
}
public void invalidate()
{
if(!isValid)
{
throw new IllegalStateException("Attempt to access an invalidated session");
}
else
{
sc.removeSession(sessionID);
isValid = false;
return;
}
}
public void putValue(String s, Object obj)
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
removeValue(s);
sessionObjects.put(s, obj);
if(obj instanceof HttpSessionBindingListener)
((HttpSessionBindingListener)obj).valueBound(new HttpSessionBindingEvent(this, s));
}
public Object getValue(String s)
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
else
return sessionObjects.get(s);
}
public void removeValue(String s)
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
Object obj = sessionObjects.get(s);
if(obj != null)
sessionObjects.remove(s);
if(obj instanceof HttpSessionBindingListener)
((HttpSessionBindingListener)obj).valueUnbound(new HttpSessionBindingEvent(this, s));
}
public String[] getValueNames()
{
if(!isValid)
throw new IllegalStateException("Attempt to access an invalidated session");
String as[] = new String[sessionObjects.size()];
int i = 0;
for(Enumeration enumeration = sessionObjects.keys(); enumeration.hasMoreElements();)
as[i++] = (String)enumeration.nextElement();
return as;
}
public void setMaxInactiveInterval(int max){
}
public int getMaxInactiveInterval() {
return 180;
}
public void setAttribute(String str, Object obj) {
}
public Object getAttribute(String str) {
return null;
}
public void removeAttribute(java.lang.String name) {
}
public java.util.Enumeration getAttributeNames() {
return null;
}
private String sessionID;
private long creationTime;
private long lastAccessedTime;
private Hashtable sessionObjects;
private SessionContextImpl sc;
private boolean cookieSupportDetermined;
private boolean usingCookies;
private boolean usingURL;
private Cookie cookie;
private boolean isNew;
private boolean isValid;
public javax.servlet.ServletContext getServletContext()
{
return null;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?