JSP隐藏对象

JSP内置的隐藏对象有out、request、response、config、session、application、page、pageContext、exception。

一、out输出流对象
    void append(CharSequence cs) 向out缓存中扩展字符类输出。当缓存满或者执行out.flush()操作时,这些内容会输出到客户端浏览器。
    void clear() 清空要输出的内容。
    void flush() 将缓存内容flush到客户端浏览器。
    void println(String str) 向客户端输出内容。
    boolean isAutoFlush() 返回缓存满时是否自动flush。如果为false,缓存满时会抛出异常。
    int getBufferSize() 返回缓存大小。单位KB。
    int getRemaining() 返回缓存剩余大小。单位KB。

二、request请求对象
    void setAttribute(String name, Object value) 在request中保存一个对象。本页面内或者forward之后的页面中可以通过getAttribute(String name)方法获取该对象。
    Object getAttribute(String name) 从request中获取name对应的对象。
    String getMethod() 返回提交方式,一般为GET或者POST。
    String getParameter(String key) 返回提交的参数。
    String[] getParameterValues(String key) 返回提交的多个同名参数值。以数组形式返回。
    Enumeration getParameterNames() 返回所有提交的参数名称。
    Cookie[] getCookies() 返回所有的Cookie。
    String getContextPath() 返回应用程序路径,例如“/jspWeb”。
    String getRequestURI() 返回请求的URI路径,例如“/jsp/method.jsp”。
    void setCharacterEncoding(String encoding) 设置request的编码方式。
    String getHeader(String name) 获取request头信息。
    Enumeration getHeaderNames() 返回所有的request头名称。
    Dispatcher getRequestDispatcher() 返回Dispatcher对象。Dispatcher可执行forward操作。
    HttpSession getSession() 返回HttpSession对象。

三、response响应对象
    void clear() 清空暂存在缓冲区的输出。
    void addCookie(Cookie cookie) 设置Cookie。
    OutputStream getOutputStream() 返回服务器输出流。可以通过该输出流输出二进制信息。
    void sendRedirect(String url) 使本页面redirect到另一个页面。
    void setContentType(String contentType) 设置文档类型。HTML的文档类型为text/html。
    PrintWriter getOut() 返回out对象。
    void setHeader(String name, String value) 设置response头信息。
    void setStatus(int status) 设置response状态码。

四、config配置对象
    String getInitParameter(String name) 返回配置在web.xml中的初始化参数。
    Enumeration getInitParameterNames() 返回所有的初始化参数名称。
    ServletContext getServletContext() 返回ServletContext对象。
    String getServletNames() 返回Servlet的名称。

五、Session会话对象
    String getId() 返回session的id
    Object getAttribute(String name) 返回session中属性名为name的对象。
    Enumeration getAttributeNames() 返回session的所有属性名。
    long getCreationTime() 返回该session创建的时间。
    long getLastAccessedTime() 返回该session最后一次访问的时间。
    int getMaxInactiveInterval() 返回session的最大允许的间隔时间。单位为秒。
    void setAttribute(String name, Object value) 设置session。
    void setMaxInactiveInterval(long second) 设置最大允许的时间间隔。

六、application应用程序对象
    Object getAttribute(String name) 返回application中属性名为name的对象。
    Enumeration getAttributeNames() 返回application中的所有属性名。
    void setAttribute(String name, Object value) 设置application属性。
    void removeAttribute(String name) 移除application属性。
    String getInitParameter(String name) 返回全局初始化参数。
    Enumeration getInitParameterNames() 返回所有的全局初始化参数。
    String getMimeType(String filename) 返回文件的文档类型。例如getMimeType(“abc.html”)将返回“text/html”。
    String getRealPath(String relativePath) 返回web应用程序内相对网址对应的绝对路径。

七、page页面对象

八、pageContext页面上下文对象
    Object findAttribute(String name) 在JSP页面中查找变量。
    void forward(String url) forward到另一个页面。
    Object getAttribute(String name) 返回属性。
    Object getAttribute(String name, int scope) 返回指定范围内的属性。范围包括PAGE_SCOPE、REQUEST_SCOPE、SESSION_REQUEST、APPLICATION_SCOPE。
    JspWriter getOut() 返回out对象。
    Object getPage() 返回page对象。
    ServletRequest getRequest() 返回request对象。
    ServletResponse getResponse() 返回response对象。
    HttpSession getSession() 返回session对象。

九、 exception异常对象
    errorPage=”error.jsp”
    isErrorPage=”true”

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值