JSP的九大内置对象

                                    JSP内置对象(9个经常使用的内置对象) java

   1.request对象 数组

客户端的请求信息被封装在request对象中,经过它才能了解到客户的需求,服务器

而后作出响应。它是HttpServletRequest类的实例。session

序号方法说明app

  1. objectgetAttribute(Stringname) 返回指定属性的属性值
  2. EnumerationgetAttributeNames() 返回全部可用属性名的枚举
  3. StringgetCharacterEncoding() 返回字符编码方式
  4. intgetContentLength() 返回请求体的长度(以字节数)
  5. StringgetContentType() 获得请求体的MIME类型
  6. ServletInputStreamgetInputStream() 获得请求体中一行的二进制流
  7. StringgetParameter(Stringname) 返回name指定参数的参数值
  8. EnumerationgetParameterNames() 返回可用参数名的枚举
  9. String[]getParameterValues(Stringname) 返回包含参数name的全部值的数组
  10. StringgetProtocol() 返回请求用的协议类型及版本号
  11. StringgetScheme() 返回请求用的计划名,如:http.https及ftp等
  12. StringgetServerName() 返回接受请求的服务器主机名
  13. intgetServerPort() 返回服务器接受此请求所用的端口号
  14. BufferedReadergetReader() 返回解码过了的请求体
  15. StringgetRemoteAddr() 返回发送此请求的客户端IP地址
  16. StringgetRemoteHost() 返回发送此请求的客户端主机名
  17. voidsetAttribute(Stringkey,Objectobj) 设置属性的属性值
  18. StringgetRealPath(Stringpath) 返回一虚拟路径的真实路径   ide

2.response对象this

  1. response对象包含了响应客户请求的有关信息,但在JSP中不多直接用到它。
  2. 它是HttpServletResponse类的实例。
  3. 序号方法说明
  4. 1StringgetCharacterEncoding() 返回响应用的是何种字符编码
  5. 2ServletOutputStreamgetOutputStream() 返回响应的一个二进制输出流
  6. 3PrintWritergetWriter() 返回能够向客户端输出字符的一个对象
  7. 4voidsetContentLength(intlen) 设置响应头长度
  8. 5voidsetContentType(Stringtype) 设置响应的MIME类型
  9. 6sendRedirect(java.lang.Stringlocation) 从新定向客户端的请求

   3.session对象 编码

session对象指的是客户端与服务器的一次会话,从客户连到服务器的一个spa

WebApplication开始,直到客户端与服务器断开链接为止。它是HttpSession线程

类的实例.

序号方法说明

  1. longgetCreationTime() 返回SESSION建立时间
  2. publicStringgetId() 返回SESSION建立时JSP引擎为它设的唯一ID号
  3. longgetLastAccessedTime() 返回此SESSION里客户端最近一次请求时间
  4. intgetMaxInactiveInterval() 返回两次请求间隔多长时间此SESSION被取
  5. 消(ms)
  6. String[]getValueNames() 返回一个包含此SESSION中全部可用属性的数
  7. voidinvalidate() 取消SESSION,使SESSION不可用
  8. booleanisNew() 返回服务器建立的一个SESSION,客户端是否已经加入
  9. voidremoveValue(Stringname) 删除SESSION中指定的属性
  10. voidsetMaxInactiveInterval() 设置两次请求间隔多长时间此SESSION被取

消(ms)

   4.out对象

  1. out对象是JspWriter类的实例,是向客户端输出内容经常使用的对象
  2. 序号方法说明
  3. voidclear() 清除缓冲区的内容
  4. voidclearBuffer() 清除缓冲区的当前内容
  5. voidflush() 清空流
  6. intgetBufferSize() 返回缓冲区以字节数的大小,如不设缓冲区则为0
  7. intgetRemaining() 返回缓冲区还剩余多少可用
  8. booleanisAutoFlush() 返回缓冲区满时,是自动清空仍是抛出异常
  9. voidclose() 关闭输出流

   5.page对象

  1. page对象就是指向当前JSP页面自己,有点象类中的this指针,它是
  2. java.lang.Object类的实例
  3. 序号方法说明
  4. classgetClass 返回此Object的类
  5. inthashCode() 返回此Object的hash码
  6. booleanequals(Objectobj) 判断此Object是否与指定的Object对象相等
  7. voidcopy(Objectobj) 把此Object拷贝到指定的Object对象中
  8. Objectclone() 克隆此Object对象
  9. StringtoString() 把此Object对象转换成String类的对象
  10. voidnotify() 唤醒一个等待的线程
  11. voidnotifyAll() 唤醒全部等待的线程
  12. voidwait(inttimeout) 使一个线程处于等待直到timeout结束或被唤醒
  13. voidwait() 使一个线程处于等待直到被唤醒
  14. voidenterMonitor() 对Object加锁
  15. voidexitMonitor() 对Object开锁

   6.application对象

application对象实现了用户间数据的共享,可存放全局变量。它开始于服务器

的启动,直到服务器的关闭,在此期间,此对象将一直存在;这样在用户的前

后链接或不一样用户之间的链接中,能够对此对象的同一属性进行操做;在任何

地方对此对象属性的操做,都将影响到其余用户对此的访问。服务器的启动和

关闭决定了application对象的生命。它是ServletContext类的实例。

序号方法说明

  1. ObjectgetAttribute(Stringname) 返回给定名的属性值
  2. EnumerationgetAttributeNames() 返回全部可用属性名的枚举
  3. voidsetAttribute(Stringname,Objectobj) 设定属性的属性值
  4. voidremoveAttribute(Stringname) 删除一属性及其属性值
  5. StringgetServerInfo() 返回JSP(SERVLET)引擎名及版本号
  6. StringgetRealPath(Stringpath) 返回一虚拟路径的真实路径
  7. ServletContextgetContext(Stringuripath) 返回指定WebApplication的application对象
  8. intgetMajorVersion() 返回服务器支持的ServletAPI的最大版本号
  9. intgetMinorVersion() 返回服务器支持的ServletAPI的最大版本号
  10. StringgetMimeType(Stringfile) 返回指定文件的MIME类型
  11. URLgetResource(Stringpath) 返回指定资源(文件及目录)的URL路径
  12. InputStreamgetResourceAsStream(Stringpath) 返回指定资源的输入流
  13. RequestDispatchergetRequestDispatcher(Stringuripath) 返回指定资源的RequestDispatcher对象
  14. ServletgetServlet(Stringname) 返回指定名的Servlet
  15. EnumerationgetServlets() 返回全部Servlet的枚举
  16. EnumerationgetServletNames() 返回全部Servlet名的枚举
  17. voidlog(Stringmsg) 把指定消息写入Servlet的日志文件
  18. voidlog(Exceptionexception,Stringmsg) 把指定异常的栈轨迹及错误消息写入Servlet的日志文件
  19. voidlog(Stringmsg,Throwablethrowable) 把栈轨迹及给出的Throwable异常的说明信息写入Servlet的日志文件

   7.exception对象

exception对象是一个例外对象,当一个页面在运行过程当中发生了例外,就产

生这个对象。若是一个JSP页面要应用此对象,就必须把isErrorPage设为true,

不然没法编译。他其实是java.lang.Throwable的对象

序号方法说明

  1. StringgetMessage() 返回描述异常的消息
  2. StringtoString() 返回关于异常的简短描述消息
  3. voidprintStackTrace() 显示异常及其栈轨迹
  4. ThrowableFillInStackTrace() 重写异常的执行栈轨迹

   8.pageContext对象

pageContext对象提供了对JSP页面内全部的对象及名字空间的访问,也就是

说他能够访问到本页所在的SESSION,也能够取本页面所在的application的

某一属性值,他至关于页面中全部功能的集大成者,它的本类名也叫

pageContext。

序号方法说明

  1. JspWritergetOut() 返回当前客户端响应被使用的JspWriter流(out)
  2. HttpSessiongetSession() 返回当前页中的HttpSession对象(session)
  3. ObjectgetPage() 返回当前页的Object对象(page)
  4. ServletRequestgetRequest() 返回当前页的ServletRequest对象(request)
  5. ServletResponsegetResponse() 返回当前页的ServletResponse对象(response)
  6. ExceptiongetException() 返回当前页的Exception对象(exception)
  7. ServletConfiggetServletConfig() 返回当前页的ServletConfig对象(config)
  8. ServletContextgetServletContext() 返回当前页的ServletContext对象(application)
  9. voidsetAttribute(Stringname,Objectattribute) 设置属性及属性值
  10. voidsetAttribute(Stringname,Objectobj,intscope) 在指定范围内设置属性及属性值
  11. publicObjectgetAttribute(Stringname) 取属性的值
  12. ObjectgetAttribute(Stringname,intscope) 在指定范围内取属性的值
  13. publicObjectfindAttribute(Stringname) 寻找一属性,返回起属性值或NULL
  14. voidremoveAttribute(Stringname) 删除某属性
  15. voidremoveAttribute(Stringname,intscope) 在指定范围删除某属性
  16. intgetAttributeScope(Stringname) 返回某属性的做用范围
  17. EnumerationgetAttributeNamesInScope(intscope) 返回指定范围内可用的属性名枚举
  18. voidrelease() 释放pageContext所占用的资源
  19. voidforward(StringrelativeUrlPath) 使当前页面重导到另外一页面
  20. voidinclude(StringrelativeUrlPath) 在当前位置包含另外一文件

   9.config对象

config对象是在一个Servlet初始化时,JSP引擎向它传递信息用的,此信息包括Servlet初始化时所要用到的参数(经过属性名和属性值构成)以及服务器的有关信息(经过传递一个ServletContext对象)

相关文章
相关标签/搜索