<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ourday

    ourday

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      8 Posts :: 2 Stories :: 11 Comments :: 0 Trackbacks
       

    1.request對象

        客戶端的請求信息被封裝在request對象中,通過它才能了解到客戶的需求,然后做出響應(yīng)。它是HttpServletRequest類的實(shí)例。

    序號 方 法 說 明
    1 object getAttribute(String name) 返回指定屬性的屬性值
    2 Enumeration getAttributeNames() 返回所有可用屬性名的枚舉
    3 String getCharacterEncoding() 返回字符編碼方式
    4 int getContentLength() 返回請求體的長度(以字節(jié)數(shù))
    5 String getContentType() 得到請求體的MIME類型
    6 ServletInputStream getInputStream() 得到請求體中一行的二進(jìn)制流
    7 String getParameter(String name) 返回name指定參數(shù)的參數(shù)值
    8 Enumeration getParameterNames() 返回可用參數(shù)名的枚舉
    9 String[] getParameterValues(String name) 返回包含參數(shù)name的所有值的數(shù)組
    10 String getProtocol() 返回請求用的協(xié)議類型及版本號
    11 String getScheme() 返回請求用的計(jì)劃名,如:http.https及ftp等
    12 String getServerName() 返回接受請求的服務(wù)器主機(jī)名
    13 int getServerPort() 返回服務(wù)器接受此請求所用的端口號
    14 BufferedReader getReader() 返回解碼過了的請求體
    15 String getRemoteAddr() 返回發(fā)送此請求的客戶端IP地址
    16 String getRemoteHost() 返回發(fā)送此請求的客戶端主機(jī)名
    17 void setAttribute(String key,Object obj) 設(shè)置屬性的屬性值
    18 String getRealPath(String path) 返回一虛擬路徑的真實(shí)路徑
    19    
    20    
         

    <%@ page contentType="text/html;charset=gb2312"%>
    <%request.setCharacterEncoding("gb2312");%>
    <html>
    <head>
    <title>request
    對象_1</title>
    </head>
    <body bgcolor="#FFFFF0">
    <form action="" method="post">
    <input type="text" name="qwe">
    <input type="submit" value="
    提交">
    </form>
    請求方式:<%=request.getMethod()%><br>
    請求的資源:<%=request.getRequestURI()%><br>
    請求用的協(xié)議:<%=request.getProtocol()%><br>
    請求的文件名:<%=request.getServletPath()%><br>
    請求的服務(wù)器的IP<%=request.getServerName()%><br>
    請求服務(wù)器的端口:<%=request.getServerPort()%><br>
    客戶端IP地址:<%=request.getRemoteAddr()%><br>
    客戶端主機(jī)名:<%=request.getRemoteHost()%><br>
    表單提交來的值:<%=request.getParameter("qwe")%><br>
    </body>
    </html>
    <%@ page contentType="text/html;charset=gb2312"%>
    <%request.setCharacterEncoding("gb2312");%>
    <%@ page import="java.util.Enumeration"%>
    <html>
    <head>
    <title>request
    對象_2</title>
    </head>
    <body bgcolor="#FFFFF0">
    <form action="" method="post">
      
    用戶名:<input type="text" name="username">&nbsp;&nbsp;
      
    碼:<input type="text" name="userpass">&nbsp;&nbsp;
       <input type="submit" value="
    進(jìn)入" >
    </form>
    <%
    String str="";
    if(request.getParameter("username")!=null && request.getParameter("userpass")!=null){
       Enumeration enumt = request.getParameterNames();
       while(enumt.hasMoreElements()){
          str=enumt.nextElement().toString();
          out.println(str+":"+request.getParameter(str)+"<br>");
       }
    }
    %>
    </body>
    </html>
    <%@ page contentType="text/html;charset=gb2312"%>
    <%request.setCharacterEncoding("gb2312");%>
    <html>
    <head>
       <title>request
    對象_3</title>
    </head>
    <body bgcolor="#FFFFF0">
    <form action="" method="post">
    擅長:<input type="checkbox" name="cb" value="ON1">VC++&nbsp;
           <input type="checkbox" name="cb" value="ON2">JAVA&nbsp;
           <input type="checkbox" name="cb" value="ON3">DELPHI&nbsp;
           <input type="checkbox" name="cb" value="ON4">VB&nbsp;
           <br>
           <input type="submit" value="
    進(jìn)入" name="qwe">
    </form>
    <%
    if(request.getParameter("qwe")!=null ){
       for(int i=0;i<request.getParameterValues("cb").length;i++){
          out.println("cb"+i+":"+request.getParameterValues("cb")[i]+"<br>");
       }
       out.println(request.getParameter("qwe"));
    }
    %>
    </body>
    </html>
     

     

    2.response對象

        response對象包含了響應(yīng)客戶請求的有關(guān)信息,但在JSP中很少直接用到它。它是HttpServletResponse類的實(shí)例。

    序號 方 法 說 明
    1 String getCharacterEncoding() 返回響應(yīng)用的是何種字符編碼
    2 ServletOutputStream getOutputStream() 返回響應(yīng)的一個(gè)二進(jìn)制輸出流
    3 PrintWriter getWriter() 返回可以向客戶端輸出字符的一個(gè)對象
    4 void setContentLength(int len) 設(shè)置響應(yīng)頭長度
    5 void setContentType(String type) 設(shè)置響應(yīng)的MIME類型
    6 sendRedirect(java.lang.String location) 重新定向客戶端的請求
    7    
    8    
         

    3.session對象

        session對象指的是客戶端與服務(wù)器的一次會話,從客戶連到服務(wù)器的一個(gè)WebApplication開始,直到客戶端與服務(wù)器斷開連接為止。它是HttpSession類的實(shí)例.

    序號 方 法 說 明
    1 long getCreationTime() 返回SESSION創(chuàng)建時(shí)間
    2 public String getId() 返回SESSION創(chuàng)建時(shí)JSP引擎為它設(shè)的惟一ID號
    3 long getLastAccessedTime() 返回此SESSION里客戶端最近一次請求時(shí)間
    4 int getMaxInactiveInterval() 返回兩次請求間隔多長時(shí)間此SESSION被取消(ms)
    5 String[] getValueNames() 返回一個(gè)包含此SESSION中所有可用屬性的數(shù)組
    6 void invalidate() 取消SESSION,使SESSION不可用
    7 boolean isNew() 返回服務(wù)器創(chuàng)建的一個(gè)SESSION,客戶端是否已經(jīng)加入
    8 void removeValue(String name) 刪除SESSION中指定的屬性
    9 void setMaxInactiveInterval() 設(shè)置兩次請求間隔多長時(shí)間此SESSION被取消(ms)
    10    
    11    
    12    
    13    
    14    
    15    
         

    <%@ page contentType="text/html;charset=gb2312"%>
    <%@ page import="java.util.*" %>
    <html>
    <head><title>session對象_例1</title><head>
    <body><br>
       session的創(chuàng)建時(shí)間:<%=session.getCreationTime()%>&nbsp;&nbsp;<%=new Date(session.getCreationTime())%><br><br>
       session的Id號:<%=session.getId()%><br><br>
       客戶端最近一次請求時(shí)間:<%=session.getLastAccessedTime()%>&nbsp;&nbsp;<%=new java.sql. Time(session.getLastAccessedTime())%><br><br>
       兩次請求間隔多長時(shí)間此SESSION被取消(ms):<%=session.getMaxInactiveInterval()%><br><br>
       是否是新創(chuàng)建的一個(gè)SESSION:<%=session.isNew()?"是":"否"%><br><br>
    <%
    session.putValue("name","霖苑編程");
    session.putValue("nmber","147369");
    %>
    <%
    for(int i=0;i<session.getValueNames().length;i++)
    out.println(session.getValueNames()[i]+"="+session.getValue(session.getValueNames()[i]));
    %>
    <!--返回的是從格林威治時(shí)間(GMT)1970年01月01日0:00:00起到計(jì)算當(dāng)時(shí)的毫秒數(shù)-->
    </body>
    </html>


    4.out對象

        out對象是JspWriter類的實(shí)例,是向客戶端輸出內(nèi)容常用的對象

    序號 方 法 說 明
    1 void clear() 清除緩沖區(qū)的內(nèi)容
    2 void clearBuffer() 清除緩沖區(qū)的當(dāng)前內(nèi)容
    3 void flush() 清空流
    4 int getBufferSize() 返回緩沖區(qū)以字節(jié)數(shù)的大小,如不設(shè)緩沖區(qū)則為0
    5 int getRemaining() 返回緩沖區(qū)還剩余多少可用
    6 boolean isAutoFlush() 返回緩沖區(qū)滿時(shí),是自動清空還是拋出異常
    7 void close() 關(guān)閉輸出流
    8    
    9    
    10    
    11    
    12    
    13    
    14    
    15    
         

    <%@page contentType="text/html;charset=gb2312"%>
    <html><head><title>out對象_例1:緩存測試</title></head>
    <%@page buffer="1kb"%>
    <body>
    <%
    for(int i=0;i<2000;i++)
    out.println(i+"{"+out.getRemaining()+"}");
    %><br>
    緩存大小:<%=out.getBufferSize()%><br>
    剩余緩存大小:<%=out.getRemaining()%><br>
    自動刷新:<%=out.isAutoFlush()%><br>
    <%--out.clearBuffer();--%>
    <%--out.clear();--%>
    <!--缺省情況下:服務(wù)端要輸出到客戶端的內(nèi)容,不直接寫到客戶端,而是先寫到一個(gè)輸出緩沖區(qū)中.只有在下面三中情況下,才會把該緩沖區(qū)的內(nèi)容輸出到客戶端上:
    1.該JSP網(wǎng)頁已完成信息的輸出
    2.輸出緩沖區(qū)已滿
    3.JSP中調(diào)用了out.flush()或response.flushbuffer()
    -->
    </body>
    </html>


    5.page對象

        page對象就是指向當(dāng)前JSP頁面本身,有點(diǎn)象類中的this指針,它是java.lang.Object類的實(shí)例

    序號 方 法 說 明
    1 class getClass 返回此Object的類
    2 int hashCode() 返回此Object的hash碼
    3 boolean equals(Object obj) 判斷此Object是否與指定的Object對象相等
    4 void copy(Object obj) 把此Object拷貝到指定的Object對象中
    5 Object clone() 克隆此Object對象
    6 String toString() 把此Object對象轉(zhuǎn)換成String類的對象
    7 void notify() 喚醒一個(gè)等待的線程
    8 void notifyAll() 喚醒所有等待的線程
    9 void wait(int timeout) 使一個(gè)線程處于等待直到timeout結(jié)束或被喚醒
    10 void wait() 使一個(gè)線程處于等待直到被喚醒
    11 void enterMonitor() 對Object加鎖
    12 void exitMonitor() 對Object開鎖
    13    
    14    
    15    
         

    6.application對象

        application對象實(shí)現(xiàn)了用戶間數(shù)據(jù)的共享,可存放全局變量。它開始于服務(wù)器的啟動,直到服務(wù)器的關(guān)閉,在此期間,此對象將一直存在;這樣在用戶的前后連接或不同用戶之間的連接中,可以對此對象的同一屬性進(jìn)行操作;在任何地方對此對象屬性的操作,都將影響到其他用戶對此的訪問。服務(wù)器的啟動和關(guān)閉決定了application對象的生命。它是ServletContext類的實(shí)例。

    序號 方 法 說 明
    1 Object getAttribute(String name) 返回給定名的屬性值
    2 Enumeration getAttributeNames() 返回所有可用屬性名的枚舉
    3 void setAttribute(String name,Object obj) 設(shè)定屬性的屬性值
    4 void removeAttribute(String name) 刪除一屬性及其屬性值
    5 String getServerInfo() 返回JSP(SERVLET)引擎名及版本號
    6 String getRealPath(String path) 返回一虛擬路徑的真實(shí)路徑
    7 ServletContext getContext(String uripath) 返回指定WebApplication的application對象
    8 int getMajorVersion() 返回服務(wù)器支持的Servlet API的最大版本號
    9 int getMinorVersion() 返回服務(wù)器支持的Servlet API的最大版本號
    10 String getMimeType(String file) 返回指定文件的MIME類型
    11 URL getResource(String path) 返回指定資源(文件及目錄)的URL路徑
    12 InputStream getResourceAsStream(String path) 返回指定資源的輸入流
    13 RequestDispatcher getRequestDispatcher(String uripath) 返回指定資源的RequestDispatcher對象
    14 Servlet getServlet(String name) 返回指定名的Servlet
    15 Enumeration getServlets() 返回所有Servlet的枚舉
    16 Enumeration getServletNames() 返回所有Servlet名的枚舉
    17 void log(String msg) 把指定消息寫入Servlet的日志文件
    18 void log(Exception exception,String msg) 把指定異常的棧軌跡及錯(cuò)誤消息寫入Servlet的日志文件
    19 void log(String msg,Throwable throwable) 把棧軌跡及給出的Throwable異常的說明信息寫入Servlet的日志文件
    20    
         

    <%@ page contentType="text/html;charset=gb2312"%>
    <html>
    <head><title>APPLICATION對象_例1</title><head>
    <body><br>
    JSP(SERVLET)引擎名及版本號:<%=application.getServerInfo()%><br><br>
    返回/application1.jsp虛擬路徑的真實(shí)路徑:<%=application.getRealPath("/application1.jsp")%><br><br>
    服務(wù)器支持的Servlet API的大版本號:<%=application.getMajorVersion()%><br><br>
    服務(wù)器支持的Servlet API的小版本號:<%=application.getMinorVersion()%><br><br>
    指定資源(文件及目錄)的URL路徑:<%=application.getResource("/application1.jsp")%><br><br><!--可以將application1.jsp換成一個(gè)目錄-->
    <br><br>
    <%
    application.setAttribute("name","霖苑計(jì)算機(jī)編程技術(shù)培訓(xùn)學(xué)校");
    out.println(application.getAttribute("name"));
    application.removeAttribute("name");
    out.println(application.getAttribute("name"));
    %>
    </body>
    </html>
    <%@ page contentType="text/html;charset=gb2312"%>
    <html>
    <head><title>APPLICATION對象_例2</title><head>
    <body><br>
    <!--由于application一直存在于服務(wù)器端,可以利用此特性對網(wǎng)頁記數(shù)-->
    <%
    if(application.getAttribute("count")==null)
    application.setAttribute("count","1");
    else
    application.setAttribute("count",Integer.toString(Integer.valueOf(application.getAttribute("count").toString()).intValue()+1));
    %>
    你是第<%=application.getAttribute("count")%>位訪問者
    </body>
    <!--由于getAttribute()方法得到的是一個(gè)Object類型對象,用getString()方法轉(zhuǎn)化為String類型-->
    <!--用Integer類的valueOf()方法把得到的String轉(zhuǎn)化成Integer的對象,在用intValue()方法得到int型,再加1,最后把計(jì)算的結(jié)果用Integer.toString()方法轉(zhuǎn)化成setAttribute()方法所要求的String類型-->
    </html>
    <%@ page contentType="text/html;charset=gb2312"%>
    <html>
    <head><title>APPLICATION對象_例3</title><head>
    <body><br>
    <!--由于application一直存在于服務(wù)器端,可以利用此特性對網(wǎng)頁記數(shù)-->
    <%
    String str=application.getAttribute("count").toString();//getAttribute("count")返回的是Object類型
    int i=0;
    if(str==null)
    application.setAttribute("count","1");
    else
    i=Integer.parseInt(str); //out.println(i);
    application.setAttribute("count",++i+"");
    %>
    你是第<%=application.getAttribute("count")%>位訪問者
    </body>
    </html>

    7.exception對象

    exception對象是一個(gè)例外對象,當(dāng)一個(gè)頁面在運(yùn)行過程中發(fā)生了例外,就產(chǎn)生這個(gè)對象。如果一個(gè)JSP頁面要應(yīng)用此對象,就必須把isErrorPage設(shè)為true,否則無法編譯。他實(shí)際上是java.lang.Throwable的對象

    序號 方 法 說 明
    1 String getMessage() 返回描述異常的消息
    2 String toString() 返回關(guān)于異常的簡短描述消息
    3 void printStackTrace() 顯示異常及其棧軌跡
    4 Throwable FillInStackTrace() 重寫異常的執(zhí)行棧軌跡
    5    
         

    8.pageContext對象

       pageContext對象提供了對JSP頁面內(nèi)所有的對象及名字空間的訪問,也就是說他可以訪問到本頁所在的SESSION,也可以取本頁面所在的application的某一屬性值,他相當(dāng)于頁面中所有功能的集大成者,它的本類名也叫pageContext。

    序號 方 法 說 明
    1 JspWriter getOut() 返回當(dāng)前客戶端響應(yīng)被使用的JspWriter流(out)
    2 HttpSession getSession() 返回當(dāng)前頁中的HttpSession對象(session)
    3 Object getPage() 返回當(dāng)前頁的Object對象(page)
    4 ServletRequest getRequest() 返回當(dāng)前頁的ServletRequest對象(request)
    5 ServletResponse getResponse() 返回當(dāng)前頁的ServletResponse對象(response)
    6 Exception getException() 返回當(dāng)前頁的Exception對象(exception)
    7 ServletConfig getServletConfig() 返回當(dāng)前頁的ServletConfig對象(config)
    8 ServletContext getServletContext() 返回當(dāng)前頁的ServletContext對象(application)
    9 void setAttribute(String name,Object attribute) 設(shè)置屬性及屬性值
    10 void setAttribute(String name,Object obj,int scope) 在指定范圍內(nèi)設(shè)置屬性及屬性值
    11 public Object getAttribute(String name) 取屬性的值
    12 Object getAttribute(String name,int scope) 在指定范圍內(nèi)取屬性的值
    13 public Object findAttribute(String name) 尋找一屬性,返回起屬性值或NULL
    14 void removeAttribute(String name) 刪除某屬性
    15 void removeAttribute(String name,int scope) 在指定范圍刪除某屬性
    16 int getAttributeScope(String name) 返回某屬性的作用范圍
    17 Enumeration getAttributeNamesInScope(int scope) 返回指定范圍內(nèi)可用的屬性名枚舉
    18 void release() 釋放pageContext所占用的資源
    19 void forward(String relativeUrlPath) 使當(dāng)前頁面重導(dǎo)到另一頁面
    20 void include(String relativeUrlPath) 在當(dāng)前位置包含另一文件
    21    
         
          

    <%@page contentType="text/html;charset=gb2312"%>
    <html><head><title>pageContext對象_例1</title></head>
    <body><br>
    <%
    request.setAttribute("name","霖苑編程");
    session.setAttribute("name","霖苑計(jì)算機(jī)編程技術(shù)培訓(xùn)");
    //session.putValue("name","計(jì)算機(jī)編程");
    application.setAttribute("name","培訓(xùn)");
    %>
    request設(shè)定的值:<%=pageContext.getRequest().getAttribute("name")%><br>
    session設(shè)定的值:<%=pageContext.getSession().getAttribute("name")%><br>
    application設(shè)定的值:<%=pageContext.getServletContext().getAttribute("name")%><br>
    范圍1內(nèi)的值:<%=pageContext.getAttribute("name",1)%><br>
    范圍2內(nèi)的值:<%=pageContext.getAttribute("name",2)%><br>
    范圍3內(nèi)的值:<%=pageContext.getAttribute("name",3)%><br>
    范圍4內(nèi)的值:<%=pageContext.getAttribute("name",4)%><br>
    <!--從最小的范圍page開始,然后是reques、session以及application-->
    <%pageContext.removeAttribute("name",3);%>
    pageContext修改后的session設(shè)定的值:<%=session.getValue("name")%><br>
    <%pageContext.setAttribute("name","應(yīng)用技術(shù)培訓(xùn)",4);%>
    pageContext修改后的application設(shè)定的值:<%=pageContext.getServletContext().getAttribute("name")%><br>
    值的查找:<%=pageContext.findAttribute("name")%><br>
    屬性name的范圍:<%=pageContext.getAttributesScope("name")%><br>
    </body></html>

    9.config對象

       config對象是在一個(gè)Servlet初始化時(shí),JSP引擎向它傳遞信息用的,此信息包括Servlet初始化時(shí)所要用到的參數(shù)(通過屬性名和屬性值構(gòu)成)以及服務(wù)器的有關(guān)信息(通過傳遞一個(gè)ServletContext對象)

    序號 方 法 說 明
    1 ServletContext getServletContext() 返回含有服務(wù)器相關(guān)信息的ServletContext對象
    2 String getInitParameter(String name) 返回初始化參數(shù)的值
    3 Enumeration getInitParameterNames() 返回Servlet初始化所需所有參數(shù)的枚舉
    4    
    5   

    posted on 2008-09-20 11:45 ourday 閱讀(821) 評論(1)  編輯  收藏

    Feedback

    # re: jsp九大內(nèi)置對象的方法 2008-10-29 18:13 ourday
    好  回復(fù)  更多評論
      


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 美女被免费网站在线视频免费| 免费的涩涩视频在线播放| 久久精品国产亚洲77777| 成年女人色毛片免费看| 五月天国产成人AV免费观看| 国产成人99久久亚洲综合精品| 亚洲日韩一区二区三区| 久久精品国产亚洲精品| 蜜臀AV免费一区二区三区| 亚洲AV无码国产一区二区三区| 日本阿v免费费视频完整版| 曰批全过程免费视频免费看| 久久精品国产亚洲麻豆| 在线免费观看污网站| 国产免费MV大全视频网站| 亚洲制服丝袜在线播放| 亚洲国产一区二区视频网站| 亚洲香蕉免费有线视频| 国产VA免费精品高清在线| 456亚洲人成在线播放网站| 三上悠亚亚洲一区高清| 午夜时刻免费入口| 99视频免费观看| 九九免费观看全部免费视频| 亚洲国产精品成人综合久久久 | 亚洲天堂电影在线观看| 男人的天堂亚洲一区二区三区| 久久亚洲AV成人无码软件| 免费一级黄色毛片| 日本亚洲免费无线码| 91av免费观看| 三根一起会坏掉的好痛免费三级全黄的视频在线观看 | 免费一级一片一毛片| jjizz全部免费看片| 国产高清视频免费在线观看| 国内精品久久久久影院亚洲| 亚洲综合一区二区国产精品| 亚洲性日韩精品国产一区二区| 一级黄色免费大片| 欧洲 亚洲 国产图片综合| 激情内射亚洲一区二区三区|