`
izuoyan
  • 浏览: 8934396 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Jsp9个内置对象详解

 
阅读更多

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

1.request对象

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

然后做出响应。它是HttpServletRequest类的实例。

序号方法说明

  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) 返回一虚拟路径的真实路径
  19. 2.response对象
  20. response对象包含了响应客户请求的有关信息,但在JSP中很少直接用到它。
  21. 它是HttpServletResponse类的实例。
  22. 序号方法说明
  23. 1StringgetCharacterEncoding() 返回响应用的是何种字符编码
  24. 2ServletOutputStreamgetOutputStream() 返回响应的一个二进制输出流
  25. 3PrintWritergetWriter() 返回可以向客户端输出字符的一个对象
  26. 4voidsetContentLength(intlen) 设置响应头长度
  27. 5voidsetContentType(Stringtype) 设置响应的MIME类型
  28. 6sendRedirect(java.lang.Stringlocation) 重新定向客户端的请求

3.session对象

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

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对象)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics