JSP内置对象及方法有哪些(jsp,开发技术)

时间:2024-05-05 21:56:33 作者 : 石家庄SEO 分类 : 开发技术
  • TAG :

    JSP%E5%86%85%E7%BD%AE%E5%AF%B9%E8%B1%A1%E5%8F%8A%E6%96%B9%E6%B3%95%E6%9C%89%E5%93%AA%E4%BA%9B

接下来,请跟着小编一起来学习吧!

request javax.servlet.http.HttpServletRequest request

response javax.servlet.http.HttpServletResponse response

pageContext javax.servlet.jsp.PageContext page

session javax.servlet.http.HtpSession session

application javax.servlet.jsp.ServletContext application

out javax.servlet.jsp.JspWriter page

config javax.servlet.ServletConfig page

page java.lang.Object page

exception java.lang.Throwable page

第一类:与Servlet有关:page和config

第二类:与Input/Output有关:out,request和response

第三类:与Context有关:application,session和pageContext

第四类:与Error有关:exceptio

page:就是设置的属性只能在当前页面有效。通过pageContext的setAttribute()和getAttribute()。

request:指属性在一次请求范围内有效。如果页面从给一个页面跳转到另一个页面,那么该属性就失效了。这里所指的跳转是指客户端跳转,比如客户单击超链接跳转到其他页面或者通过浏览器地址栏浏览其他页面。如果使用服务器端跳转<jsp:forward>,则该属性仍然生效。同理使用request对象的setAttribute()和getAttribute()。

session:指客户浏览器与服务器一次会话范围内,如果服务器断开连接,那么属性就失效了。同理通过session对象的setAttribute()和getAttribute()。session范围的例外比如重新打开一个浏览器。

application:指在整个服务器范围,知道服务器停止以后才会失效。同理通过application对象的setAttribute()和getAttribute()。application范围就是保存的属性只要服务器不重启,就能在任意页面中获取,就算重新打开浏览器也是可以获取属性的。

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

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

objectgetAttribute(Stringname)返回指定属性的属性值

EnumerationgetAttributeNames()返回所有可用属性名的枚举

StringgetCharacterEncoding()返回字符编码方式

intgetContentLength()返回请求体的长度(以字节数)

StringgetContentType()得到请求体的MIME类型

ServletInputStreamgetInputStream()得到请求体中一行的二进制流

StringgetParameter(Stringname)返回name指定参数的参数值

EnumerationgetParameterNames()返回可用参数名的枚举

String[]getParameterValues(Stringname)返回包含参数name的所有值的数组

StringgetProtocol()返回请求用的协议类型及版本号

StringgetScheme()返回请求用的计划名,如:http.https及ftp等

StringgetServerName()返回接受请求的服务器主机名

intgetServerPort()返回服务器接受此请求所用的端口号

BufferedReadergetReader()返回解码过了的请求体

StringgetRemoteAddr()返回发送此请求的客户端IP地址

StringgetRemoteHost()返回发送此请求的客户端主机名

voidsetAttribute(Stringkey,Objectobj)设置属性的属性值

StringgetRealPath(Stringpath)返回一虚拟路径的真实路径

longgetCreationTime()返回SESSION创建时间

publicStringgetId()返回SESSION创建时JSP引擎为它设的惟一ID号

longgetLastAccessedTime()返回此SESSION里客户端最近一次请求时间

intgetMaxInactiveInterval()返回两次请求间隔多长时间此SESSION被取

String[]getValueNames()返回一个包含此SESSION中所有可用属性的数组

voidinvalidate()取消SESSION,使SESSION不可用

booleanisNew()返回服务器创建的一个SESSION,客户端是否已经加入

voidremoveValue(Stringname)删除SESSION中指定的属性

voidsetMaxInactiveInterval()设置两次请求间隔多长时间此SESSION被取消(ms)

voidclear()清除缓冲区的内容

voidclearBuffer()清除缓冲区的当前内容

voidflush()清空流

intgetBufferSize()返回缓冲区以字节数的大小,如不设缓冲区则为0

intgetRemaining()返回缓冲区还剩余多少可用

booleanisAutoFlush()返回缓冲区满时,是自动清空还是抛出异常

voidclose()关闭输出流

classgetClass返回此Object类

inthashCode()返回此Object的hash码

booleanequals(Objectobj)判断此Object是否与指定的Object对象相等

voidcopy(Objectobj)把此Object拷贝到指定的Object对象中

Objectclone()克隆此Object对象

StringtoString()把此Object对象转换成String类的对象

voidnotify()唤醒一个等待的线程

voidnotifyAll()唤醒所有等待的线程

voidwait(inttimeout)使一个线程处于等待直到timeout结束或被唤醒

voidwait()使一个线程处于等待直到被唤醒

voidenterMonitor()对Object加锁

voidexitMonitor()对Object开锁

ObjectgetAttribute(Stringname)返回给定名的属性值

EnumerationgetAttributeNames()返回所有可用属性名的枚举

voidsetAttribute(Stringname,Objectobj)设定属性的属性值

voidremoveAttribute(Stringname)删除一属性及其属性值

StringgetServerInfo()返回JSP(SERVLET)引擎名及版本号

StringgetRealPath(Stringpath)返回一虚拟路径的真实路径

ServletContextgetContext(Stringuripath)返回指定WebApplication的application对象

intgetMajorVersion()返回服务器支持的ServletAPI的最大版本号

intgetMinorVersion()返回服务器支持的ServletAPI的最大版本号

StringgetMimeType(Stringfile)返回指定文件的MIME类型

URLgetResource(Stringpath)返回指定资源(文件及目录)的URL路径

InputStreamgetResourceAsStream(Stringpath)返回指定资源的输入流

RequestDispatchergetRequestDispatcher(Stringuripath)返回指定资源的RequestDispatcher对象

ServletgetServlet(Stringname)返回指定名的Servlet

EnumerationgetServlets()返回所有Servlet的枚举

EnumerationgetServletNames()返回所有Servlet名的枚举

voidlog(Stringmsg)把指定消息写入Servlet的日志文件

voidlog(Exceptionexception,Stringmsg)把指定异常的栈轨迹及错误消息写入Servlet的日志文件

voidlog(Stringmsg,Throwablethrowable)把栈轨迹及给出的Throwable异常的说明信息写入Servlet的日志文件

StringgetMessage()返回描述异常的消息

StringtoString()返回关于异常的简短描述消息

voidprintStackTrace()显示异常及其栈轨迹

ThrowableFillInStackTrace()重写异常的执行栈轨迹

JspWritergetOut()返回当前客户端响应被使用的JspWriter流(out)

HttpSessiongetSession()返回当前页中的HttpSession对象(session)

ObjectgetPage()返回当前页的Object对象(page)

ServletRequestgetRequest()返回当前页的ServletRequest对象(request)

ServletResponsegetResponse()返回当前页的ServletResponse对象(response)

ExceptiongetException()返回当前页的Exception对象(exception)

ServletConfiggetServletConfig()返回当前页的ServletConfig对象(config)

ServletContextgetServletContext()返回当前页的ServletContext对象(application)

voidsetAttribute(Stringname,Objectattribute)设置属性及属性值

voidsetAttribute(Stringname,Objectobj,intscope)在指定范围内设置属性及属性值

publicObjectgetAttribute(Stringname)取属性的值

ObjectgetAttribute(Stringname,intscope)在指定范围内取属性的值

publicObjectfindAttribute(Stringname)寻找一属性,返回起属性值或NULL

voidremoveAttribute(Stringname)删除某属性

voidremoveAttribute(Stringname,intscope)在指定范围删除某属性

intgetAttributeScope(Stringname)返回某属性的作用范围

EnumerationgetAttributeNamesInScope(intscope)返回指定范围内可用的属性名枚举

voidrelease()释放pageContext所占用的资源

voidforward(StringrelativeUrlPath)使当前页面重导到另一页面

voidinclude(StringrelativeUrlPath)在当前位置包含另一文件

本文:JSP内置对象及方法有哪些的详细内容,希望对您有所帮助,信息来源于网络。
上一篇:JSP如何连接SQL数据库下一篇:

36 人围观 / 0 条评论 ↓快速评论↓

(必须)

(必须,保密)

阿狸1 阿狸2 阿狸3 阿狸4 阿狸5 阿狸6 阿狸7 阿狸8 阿狸9 阿狸10 阿狸11 阿狸12 阿狸13 阿狸14 阿狸15 阿狸16 阿狸17 阿狸18