最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > jsp教程

jsp中的八个隐含对象

日期:08-11    来源:中国设计秀    作者:cnwebshow.com

一、page 对象 04w中国设计秀
        page对象代表jsp本身,更准确地说它代表JSP被转译后的Servlet,它可以调用Servlet类所定义的方法。04w中国设计秀

二、config 对象 04w中国设计秀
        config 对象里存放着一些Servlet 初始的数据结构。 04w中国设计秀
        config 对象实现于javax.servlet.ServletConfig 接口,它共有下列四种方法: 04w中国设计秀
        public String getInitParameter(name) 04w中国设计秀
        public java.util.Enumeration getInitParameterNames( ) 04w中国设计秀
        public ServletContext getServletContext( ) 04w中国设计秀
        public Sring getServletName( )04w中国设计秀

三、request 对象 04w中国设计秀
        request 对象包含所有请求的信息,如:请求的来源、标头、cookies和请求相关的参数值等等。 04w中国设计秀
        request 对象实现javax.servlet.http.HttpServletRequest接口的,所提供的方法可以将它分为四大类: 04w中国设计秀
        1.储存和取得属性方法; 04w中国设计秀
        void setAttribute(String name, Object value) 设定name属性的值为value 04w中国设计秀
        Enumeration getAttributeNamesInScope(int scope) 取得所有scope 范围的属性 04w中国设计秀
        Object getAttribute(String name) 取得name 属性的值 04w中国设计秀
        void removeAttribute(String name) 移除name 属性的值 04w中国设计秀
        2.取得请求参数的方法 04w中国设计秀
        String getParameter(String name) 取得name 的参数值 04w中国设计秀
        Enumeration getParameterNames( ) 取得所有的参数名称 04w中国设计秀
        String [] getParameterValues(String name) 取得所有name 的参数值 04w中国设计秀
        Map getParameterMap( ) 取得一个要求参数的Map 04w中国设计秀
        3.能够取得请求HTTP 标头的方法 04w中国设计秀
        String getHeader(String name) 取得name 的标头 04w中国设计秀
        Enumeration getHeaderNames() 取得所有的标头名称 04w中国设计秀
        Enumeration getHeaders(String name) 取得所有name 的标头 04w中国设计秀
        int getIntHeader(String name) 取得整数类型name 的标头 04w中国设计秀
        long getDateHeader(String name) 取得日期类型name 的标头 04w中国设计秀
        Cookie [] getCookies( ) 取得与请求有关的cookies 04w中国设计秀
        4.其他的方法 04w中国设计秀
        String getContextPath( ) 取得Context 路径(即站台名称) 04w中国设计秀
        String getMethod( ) 取得HTTP 的方法(GET、POST) 04w中国设计秀
        String getPRotocol( ) 取得使用的协议 (HTTP/1.1、HTTP/1.0 ) 04w中国设计秀
        String getQueryString( ) 取得请求的参数字符串,不过,HTTP的方法必须为GET 04w中国设计秀
        String getRequestedsessionId( ) 取得用户端的Session ID 04w中国设计秀
        String getRequestURI( ) 取得请求的URL,但是不包括请求的参数字符串 04w中国设计秀
        String getRemoteAddr( ) 取得用户的ip 地址 04w中国设计秀
        String getRemoteHost( ) 取得用户的主机名称 04w中国设计秀
        int getRemotePort( ) 取得用户的主机端口 04w中国设计秀
        String getRemoteUser( ) 取得用户的名称 04w中国设计秀
        void etCharacterEncoding(String encoding) 设定编码格式,用来解决窗体传递中文的问题 04w中国设计秀
        04w中国设计秀
四、response 对象 04w中国设计秀
        response 对象主要将JSP 处理数据后的结果传回到客户端。 04w中国设计秀
        response 对象是实现javax.servlet.http.HttpServletResponse 接口。response对象所提供的方法。 04w中国设计秀
        1.设定表头的方法 04w中国设计秀
        void addCookie(Cookie cookie) 新增cookie 04w中国设计秀
        void addDateHeader(String name, long date) 新增long类型的值到name标头 04w中国设计秀
        void addHeader(String name, String value) 新增String类型的值到name标头 04w中国设计秀
        void addIntHeader(String name, int value) 新增int类型的值到name标头 04w中国设计秀
        void setDateHeader(String name, long date) 指定long类型的值到name标头 04w中国设计秀
        void setHeader(String name, String value) 指定String类型的值到name标头 04w中国设计秀
        void setIntHeader(String name, int value) 指定int类型的值到name标头 04w中国设计秀
        2.设定响应状态码的方法 04w中国设计秀
        void sendError(int sc) 传送状态码(status code) 04w中国设计秀
        void sendError(int sc, String msg) 传送状态码和错误信息 04w中国设计秀
        void setStatus(int sc) 设定状态码 04w中国设计秀
        3.用来URL 重写(rewriting)的方法 04w中国设计秀
        String encodeRedirectURL(String url) 对使用sendRedirect( )方法的URL予以编码 04w中国设计秀
        04w中国设计秀
五、out 对象 04w中国设计秀
        out 对象能把结果输出到网页上。 04w中国设计秀
        out主要是用来控制管理输出的缓冲区(buffer)和输出流(output stream)。 04w中国设计秀
        void clear( ) 清除输出缓冲区的内容 04w中国设计秀
        void clearBuffer( ) 清除输出缓冲区的内容 04w中国设计秀
        void close( ) 关闭输出流,清除所有的内容 04w中国设计秀
        int getBufferSize( ) 取得目前缓冲区的大小(KB) 04w中国设计秀
        int getRemaining( ) 取得目前使用后还剩下的缓冲区大小(KB) 04w中国设计秀
        boolean isAutoFlush( ) 回传true表示缓冲区满时会自动清除;false表示不会自动清除并且产生异常处理 04w中国设计秀
        04w中国设计秀
六、session 对象 04w中国设计秀
        session对象表示目前个别用户的会话(session)状况。 04w中国设计秀
        session对象实现javax.servlet.http.HttpSession接口,HttpSession接口所提供的方法 04w中国设计秀
        long getCreationTime() 取得session产生的时间,单位是毫秒 04w中国设计秀
        String getId() 取得session 的ID 04w中国设计秀
        long getLastaccessedTime() 取得用户最后通过这个session送出请求的时间 04w中国设计秀
        long getMaxInactiveInterval() 取得最大session不活动的时间,若超过这时间,session 将会失效 04w中国设计秀
        void invalidate() 取消session 对象,并将对象存放的内容完全抛弃 04w中国设计秀
        boolean isNew() 判断session 是否为"新"的 04w中国设计秀
        void setMaxInactiveInterval(int interval) 设定最大session不活动的时间,若超过这时间,session 将会失效04w中国设计秀

七、application对象 04w中国设计秀
        application对象最常被使用在存取环境的信息。 04w中国设计秀
        因为环境的信息通常都储存在ServletContext中,所以常利用application对象来存取ServletContext中的信息。         04w中国设计秀
        application 对象实现javax.servlet.ServletContext 接口,ServletContext接口容器所提供的方法 04w中国设计秀
        int getMajorVersion( ) 取得Container主要的Servlet API版本 04w中国设计秀
        int getMinorVersion( ) 取得Container次要的Servlet API 版本 04w中国设计秀
        String getServerInfo( ) 取得Container的名称和版本 04w中国设计秀
        String getMimeType(String file) 取得指定文件的MIME 类型 04w中国设计秀
        ServletContext getContext(String uripath) 取得指定Local URL的Application context 04w中国设计秀
        String getRealPath(String path) 取得本地端path的绝对路径 04w中国设计秀
        void log(String message) 将信息写入log文件中 04w中国设计秀
        void log(String message, Throwable throwable) 将stack trace 所产生的异常信息写入log文件中 04w中国设计秀
        04w中国设计秀
八、pageContext对象 04w中国设计秀
        pageContext对象能够存取其他隐含对象。 04w中国设计秀
        1.pageContext对象存取其他隐含对象属性的方法,此时需要指定范围的参数。 04w中国设计秀
        Object getAttribute(String name, int scope) 04w中国设计秀
        Enumeration getAttributeNamesInScope(int scope) 04w中国设计秀
        void removeAttribute(String name, int scope) 04w中国设计秀
        void setAttribute(String name, Object value, int scope) 04w中国设计秀
        范围参数有四个,分别代表四种范围:PAGE_SCOPE、REQUEST_SCOPE、SESSION_SCOPE、APPLICATION_SCOPE 04w中国设计秀
        2.PageContext对象取得其他隐含对象的方法 04w中国设计秀
        Exception getException( ) 回传目前网页的异常,不过此网页要为error page, 04w中国设计秀
        JspWriter getOut( ) 回传目前网页的输出流,例如:out 04w中国设计秀
        Object getPage( ) 回传目前网页的Servlet 实体(instance),例如:page 04w中国设计秀
        ServletRequest getRequest( ) 回传目前网页的请求,例如:request 04w中国设计秀
        ServletResponse getResponse( ) 回传目前网页的响应,例如:response 04w中国设计秀
        ServletConfig getServletConfig( ) 回传目前此网页的ServletConfig 对象,例如:config 04w中国设计秀
        ServletContext getServletContext( ) 回传目前此网页的执行环境(context),例如:application 04w中国设计秀
        HttpSession getSession( ) 回传和目前网页有联系的会话(session),例如:session 04w中国设计秀
        3.PageContext对象提供取得属性的方法 04w中国设计秀
        Object getAttribute(String name, int scope) 回传name 属性,范围为scope的属性对象,回传类型为Object 04w中国设计秀
        Enumeration getAttributeNamesInScope(int scope) 回传所有属性范围为scope 的属性名称,回传类型为        Enumeration 04w中国设计秀
        int getAttributesScope(String name) 回传属性名称为name 的属性范围 04w中国设计秀
        void removeAttribute(String name) 移除属性名称为name 的属性对象 04w中国设计秀
        void removeAttribute(String name, int scope) 移除属性名称为name,范围为scope 的属性对象 04w中国设计秀
        void setAttribute(String name, Object value, int scope) 指定属性对象的名称为name、值为value、范围为scope 04w中国设计秀
        Object findAttribute(String name) 寻找在所有范围中属性名称为name 的属性对象04w中国设计秀

九、exception对象 04w中国设计秀
        若要使用exception 对象时,必须在page 指令中设定。

本文引用地址:/bc/article_46643.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明