good 原文地址:简单的记住JSP内置对象的方法PARSCOPE 作者:醉迷红楼 s:session ④ session - javax.servlet.http.HttpSession session对象表示目前个别用户的会话状态,用来识别每个用户。 方法: 1. Object getAttribute( String name ) ; 获取与指定名字相关联的session属性值。 2. Enumeration getAttributeNames() ; 取得session内所有属性的集合。 3. long getCreationTime() ; 返回session的创建时间,最小单位千分之一秒。 4. String getId() ; 取得session标识。 5. long getLastAccessedTime() ; 返回与当前session相关的客户端最后一次访问的时间,由1970-01-01算起,单位毫秒。 6. int getMaxInactiveInterval( int interval ) ; 返回总时间,以秒为单位,表示session的有效时间(session不活动时间)。-1为永不过期。 7. ServletContext getServletContext() ; 返回一个该JSP页面对应的ServletContext对象实例。 8. HttpSessionContext getSessionContext() ; 9. Object getValue( String name ) ; 取得指定名称的session变量值,不推荐使用。 10. String[] getValueNames() ; 取得所有session变量的名称的集合,不推荐使用。 11. void invalidate() ; 销毁这个session对象。 12. boolean isNew() ; 判断一个session是否由服务器产生,但是客户端并没有使用。 13. void pubValue( String name, Object value ) ; 添加一个session变量,不推荐使用。 14. void removeValue( String name ) ; 移除一个session变量的值,不推荐使用。 15. void setAttribute( String name, String value ) ; 设置指定名称的session属性值。 16. void setMaxInactiveInterval( int interval ) ; 设置session的有效期。 17. void removeAttribute( String name ) ; 移除指定名称的session属性。 c:config ⑦ config - javax.servlet.ServletConfig config对象用来存放Servlet初始的数据结构。 方法: 1. String getInitParameter( String name ) ; 返回名称为name的促使参数的值。 2. Enumeration getInitParameters() ; 返回这个JSP所有的促使参数的名称集合。 3. ServletContext getContext() ; 返回执行者的servlet上下文。 4. String getServletName() ; 返回servlet的名称。 o:out ① out - javax.servlet.jsp.jspWriter out对象用于把结果输出到网页上。 方法: 1. void clear() ; 清除输出缓冲区的内容,但是不输出到客户端。 2. void clearBuffer() ; 清除输出缓冲区的内容,并输出到客户端。 3. void close() ; 关闭输出流,清除所有内容。 4. void flush() ; 输出缓冲区里面的数据。 5. int getBufferSize() ; 获取以kb为单位的目前缓冲区大小。 6. int getRemaining() ; 获取以kb为单位的缓冲区中未被占用的空间大小。 7. boolean isAutoFlush() ; 是否自动刷新缓冲区。 8. void newLine() ; 输出一个换行字符。 9. void print( boolean b ) ; void print( char c ) ; void print( char[] s ) ; void print( double d ) ; void print( float f ) ; void print( int i ) ; void print( long l ) ; void print( Object obj ) ; void print( String s ) ; 将指定类型的数据输出到Http流,不换行。 10. void println( boolean b ) ; void println( char c ) ; void println( char[] s ) ; void println( double d ) ; void println( float f ) ; void println( int i ) ; void println( long l ) ; void println( Object obj ) ; void println( String s ) ; 将指定类型的数据输出到Http流,并输出一个换行符。 11. Appendable append( char c ) ; Appendable append( CharSequence cxq, int start, int end ) ; Appendable append( CharSequence cxq ) ; 将一个字符或者实现了CharSequence接口的对象添加到输出流的后面。 成员: int DEFAULT_BUFFER = 0 - 缺省缓冲区大小 int NO_BUFFER = -1 - writer是否处于缓冲输出状态 int UNBOUNDED_BUFFER = -2 - 是否限制缓冲区大小 p:pageContext ⑤ pageContext - javax.servlet.jsp.PageContext pageContext对象存储本JSP页面相关信息,如属性、内建对象等。 方法: 1. void setAttribute( String name, Object value, int scope ) ; void setAttribute( String name, Object value ) ; 在指定的共享范围内设置属性。 2. Object getAttribute( String name, int scope ) ; Object getAttribute( String name ) ; 取得指定共享范围内以name为名字的属性值。 3. Object findAttribute( String name ) ; 按页面、请求、会话和应用程序共享范围搜索已命名的属性。 4. void removeAttribute( String name, int scope ) ; void removeAttribute( String name ) ; 移除指定名称和共享范围的属性。 5. void forward( String url ) ; 将页面导航到指定的URL。 6. Enumeration getAttributeNamesScope( int scope ) ; 取得指定共享范围内的所有属性名称的集合。 7. int getAttributeScope( String name ) ; 取得指定属性的共享范围。 8. ErrorData getErrorDate() ; 取得页面的errorData对象。 9. Exception getException() ; 取得页面的exception对象。 10. ExpressionEvaluator getExpressionEvaluator() ; 取得页面的expressionEvaluator对象。 11. JspWriter getOut() ; 取得页面的out对象。 12. Object getPage() ; 取得页面的page对象。 13. ServletRequest getRequest() ; 取得页面的request对象。 14. ServletResponse getResponse() ; 取得页面的response对象。 15. ServletConfig getConfig() ; 取得页面的config对象。 16. ServletContext getServletContext() ; 取得页面的servletContext对象。 17. HttpSession getSession() ; 取得页面的session对象。 18. VariableResolver getVariableResolver() ; 取得页面的variableResolver对象。 19. void include( String url, boolean flush ) ; void include( String url ) ; 包含其他的资源,并指定是否自动刷新。 20. void release() ; 重置pageContext内部状态,释放所有内部引用。 21. void initialize( Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, boolean needSession, int bufferSize, boolean autoFlush ) ; 初始化未经初始化的pageContext对象。 22. BodyContext pushBody() ; BodyContext pushBody( Writer writer ) ; 保存当前的out对象,并更新pageContext中page范围内的out对象。 23. JspWrite popBody() ; 取出由pushBody()方法保存的out对象。 24. void handlePageException( Exception e ) ; void handlePageException( Thrwoable t ) ; 成员: int PAGE_SCOPE = 1 - 页面共享范围 int REQUEST_SCOPE = 2 - 请求共享范围 int SESSION_SCOPE = 3 - 会话共享范围 int APPLICATION_SCOPE = 4 - 应用程序共享范围 String PAGE = "javax.servlet.jsp.jspPage" String PAGECONTEXT = "javax.servlet.jsp.jspPageContext" String REQUEST = "javax.servlet.jsp.jspRequest" String RESPONSE = "javax.servlet.jsp.jspResponse" String CONFIG = "javax.servlet.jsp.jspConfig" String SESSION = "javax.servlet.jsp.jspSession" String OUT = "javax.servlet.jsp.jspOut" String APPLICATION = "javax.servlet.jsp.jspApplication" String EXCEPTION = "javax.servlet.jsp.jspException" e:exception ⑧ exception - java.lang.Throwable 错误对象,只有在JSP页面的page指令中指定isErrorPage="true"后,才可以在本页面使用exception对象。 方法: 1. Throwable fillInStackTrace() ; 将当前stack信息记录到exception对象中。 2. String getLocalizedMessage() ; 取得本地语系的错误提示信息。 3. String getMessage() 取得错误提示信息。 4. StackTrackElement[] getStackTrace() ; 返回对象中记录的call stack track信息。 5. Throwable initCause( Throwable cause ) ; 将另外一个异常对象嵌套进当前异常对象中。 6. Throwable getCause() ; 取出嵌套在当前异常对象中的异常。 7. void printStackTrace() ; void printStackTrace( printStream s ) ; void printStackTrace( printWriter s ) ; 打印出Throwable及其call stack trace信息。 8. void setStackTrace( StackTraceElement[] stackTrace ) 设置对象的call stack trace信息。