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

📄 pi3httpsession.java

📁 mini http server,可以集成嵌入到程序中,实现简单的web功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		if (!bValid) {
		  IllegalStateException e = new IllegalStateException();
		  throw e;
		};
	    return sid;
	}
    
    
    

    /**
     *
     * Returns the last time the client sent a request associated with
     * this session, as the number of milliseconds since midnight
     * January 1, 1970 GMT. 
     *
     * <p>Actions that your application takes, such as getting or setting
     * a value associated with the session, do not affect the access
     * time.
     *
     * <p>The last accessed time can help you manage sessions. For example,
     * the sessions can be sorted according to age to optimize some task.
     *
     * @return					a <code>long</code> integer 
     *						representing the last time 
     *						the client sent a request associated 

     *						with this session, expressed in 
     *						milliseconds since 1-1-1970 GMT
     *
     * @exception IllegalStateException		if the session is invalid
     *
     */

    public long getLastAccessedTime () {
		if (!bValid) {
		  IllegalStateException e = new IllegalStateException();
		  throw e;
		};
	    return tLastAccess;
	}
    
    
    
   /**
    * Returns the maximum time interval, in seconds, that 
    * the servlet engine will keep this session open between 
    * client requests. You can set the maximum time interval
    * with the <code>setMaxInactiveInterval</code> method.
    *
    *  
    *
    * @return		an integer specifying the number of
    *			seconds this session remains open
    *			between client requests
    *
    * @see		#setMaxInactiveInterval
    *
    *
    */
    

    public int getMaxInactiveInterval() {
	    return maxInactiveInt;
	}
    
    

   /**
    *
    * @deprecated 	As of Version 2.1, this method is
    *			deprecated and has no replacement.
    *			It will be removed in a future
    *			version of the Java Servlet API.
    *
    */

    public HttpSessionContext getSessionContext () {
	    return null;
	}
    
    
    
    
    /**
     *
     * Returns the object bound with the specified name
     * in this session or null if no object of
     * that name exists.
     *
     * @param name				a string specifying the name of the object
     *
     * @return					the object with the specified name
     *
     * @exception IllegalStateException		if the session is invalid
     *
     */
  
    public Object getValue (String name) {
		if (!bValid) {
		  IllegalStateException e = new IllegalStateException();
		  throw e;
		};
	    return obj.get(name);
	}
    
    
    

    /**
     *
     * Returns an array containing the names of all the objects
     * bound to this session. This method is useful, for example,
     * when you want to delete all the objects bound to this
     * session.
     *
     * @return					an array of strings specifying the
     *						names of all the objects bound to
     *						this session
     *
     * @exception IllegalStateException		if the session is invalid
     *
     */
    
    public String [] getValueNames() {
		if (!bValid) {
		  IllegalStateException e = new IllegalStateException();
		  throw e;
		};
		Object[] objs = obj.keySet().toArray();
		if (objs.length > 0) {
		    String[] strs = new String[objs.length];
		    System.arraycopy(objs, 0, strs, 0, objs.length);
            return strs;
		};
		return new String[0];
	};
    
    
    

    /**
     *
     * Invalidates this session and unbinds any objects bound
     * to it.
     *
     * @exception IllegalStateException		if the session is already invalid
     *
     */

    public void invalidate () {
		if (!bValid) {
		  IllegalStateException e = new IllegalStateException();
		  throw e;
		};
		String vnames[] = getValueNames();
		for (int i = 0; i < vnames.length; i++) {
		    removeValue(vnames[i]);
		};
	    bValid = false;
	}
    
    
    
    
    /**
     *
     * Returns <code>true</code> if the Web server has created a session
     * but the client has not yet joined. 
     * For example, if the server used only cookie-based sessions, and
     * the client had disabled the use of cookies, then a session would
     * be new.
     *
     * @return 					<code>true</code> if the 
     *						server has created a session, 
     *						but the client has not yet joined
     *
     * @exception IllegalStateException		if the session is invalid
     *
     *
     */

    public boolean isNew () {
		if (!bValid) {
		  IllegalStateException e = new IllegalStateException();
		  throw e;
		};
	    return bNew;
	}
    



    
    /**
     * Binds an object to this session, using the name specified.
     * If an object of the same name is already bound to the session,
     * the object is replaced.
     *
     *
     * @param name				the name to which the object is bound;
     *						cannot be null
     *
     * @param value				the object to be bound; cannot be null
     *
     * @exception IllegalStateException		if the session is invalid
     *
     */
 
    public void putValue (String name, Object value) {
		if (!bValid) {
		  IllegalStateException e = new IllegalStateException();
		  throw e;
		};
	    obj.put(name, value);
	}





    /**
     *
     * Removes the object bound with the specified name from
     * this session. If the session does not have an object
     * bound with the specified name, this method does nothing.
     *
     * <p>After this method executes, and if the object
     * implements <code>HttpSessionBindingListener</code>,
     * the object calls 
     * <code>HttpSessionBindingListener.valueUnbound</code>.
     * 
     * 
     *
     * @param name				the name of the object to
     *						remove from this session
     *
     * @exception IllegalStateException		if the session is invalid
     *
     */

    public void removeValue (String name) {
		if (!bValid) {
		  IllegalStateException e = new IllegalStateException();
		  throw e;
		};
        
		Object theObj = obj.get(name);
	    obj.remove(name);

		if (theObj instanceof HttpSessionBindingListener) {
			HttpSessionBindingListener sbl = (HttpSessionBindingListener)theObj;
			sbl.valueUnbound(new HttpSessionBindingEvent((HttpSession)this, name));
		};
	}
    
    
    

    /**
     *
     * Specifies the maximum length of time, in seconds, that the
     * servlet engine keeps this session if no user requests
     * have been made of the session.
     *
     * @param interval		An integer specifying the number
     * 				of seconds 
     *
     */
    
    public void setMaxInactiveInterval(int interval) {
	    maxInactiveInt = interval;
	}

}

⌨️ 快捷键说明

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