JSP九大隱式對象以及常用方法彙總筆記

由於隱式對象的方法實在太多,太難記。所以單獨開一篇博客記錄。以後在做項目用到這些方法的時候,會增加一些案例放到博客上,便於理解。

九大隱式對象可以分爲四類

      第一類:與輸入輸出有關的

            request請求對象

            response響應對象

            out輸出對象

      第二類:與作用域範圍有關的

            pageContext頁面作用域

            request請求作用域

            session會話作用域

            application應用作用域

      第三類:與配置有關的

            config配置對象

            page頁面本身的對象

      第四類:與異常有關的

            exception異常對象

隱式對象的常用方法:

out

      out.println();//輸出到頁面

      out.write("");//輸出到頁面

      out.append("");//追加到頁面

      out.flush();//清空緩衝區

      out.close();//關閉流

response

      response.encodeURL("");//編碼URL

      response.getCharacterEncoding();///獲取響應的字符編碼

      response.setCharacterEncoding("");//設置響應的字符編碼

      response.getContentType();//獲取頁面的內容字符編碼

      response.sendRedirect("");//重定向頁面

      response.getWriter();//獲取輸出流對象(文本流)out

      response.getOutputStream();//獲取輸出流對象(字節流)

      response.addCoodie(new Cookie("",""));//添加Cookie

request

      request.getSession();//獲取會話session對象

      request.getAttribute("");//從request作用域範圍獲取屬性

      request.setAttribute("","");//從request作用域範圍設置屬性

      request.removeAttribute("");//從查詢字符串獲取一個參數

      request.getParameter("");//從查詢字符串獲取一個參數

      request.getParameterValues("");//從查詢字符串獲取一組參數(同名的參數自動分爲一組),通常用於獲取單選、複選按鈕或下拉菜單的值

      request.getRequesDispatcher("");//獲取轉發器RequestDipatcher對象

      request.getRequestDispatcher("");//獲取轉發器對象,完成頁面轉發的功能

      request.getCharacterEncoding();//獲取請求的字符編碼

      request.setCharacterEncoding();//設置請求的字符編碼

      request.getContentType();//獲取請求頁面的內容字符編碼

      request.getCookies();//獲取請求中的Cookie對象數組

      request.getRequestURL();//獲取請求的URL

      request.getRequestURI();//獲取請求的URI

      request.getServletContext();//獲取appliction對象

      request.getServletPath();//獲取資源位置

session

      session.getAttribute("");//從session作用域範圍獲取屬性

      session.getAttribute("","")//從session作用域範圍設置屬性

      session.removeAttribute("");//從session作用域範圍移除屬性

      session.getId();//獲取會話Id

      session.getCreationTime();//獲取回話的創建時間

      session.getLastAccessedTime();//獲取會話上次訪問的時間

      session.getMaxInactiveInterval();//獲取會話的最大生存時間

      session.setMaxInactiveInerval(1000);//設置會話的最大生存時間

      session.getServletContext();//獲取應用application對象

      session.invalidate();//設置會話失效

      session.isNew();//判斷會話是否是新創建出來的,主要是第一次請求會創建會話

pageContext

      pageContext.getAttribute("");//pageContext作用域範圍獲取屬性

      pageContext.setAttribute("","");//從pageContext作用域範圍設置屬性

      pageContext.removeAttribute("");//從pageContext作用域範圍移除屬性

      pageContext.findAttribute("");//從pageContext作用域範圍查找屬性

      pageContext.getException();//獲得異常exception對象

      pageContext.getOut();//獲取輸出out對象

      pageContext.getPage();//獲取頁面page對象

      pageContext.getRequest();//獲取請求request對象

      pageContext.getResponse();//獲取請求response對象

      pageContext.getSession();//獲取會話session對象

      pageContext.getSerletContext();//獲取應用application對象

      pageContext.getServletConfig();//獲取配置config對象

      pageContext.include("");//包含頁面(<jsp:include>標準動作其實就是調用了該方法)

      pageContext.forward("");//轉發頁面(<jsp:forward>標準動作其實就是調用了該方法)

application

      application.getAttribute("");//從applivation作用域

      application.setAttribute("","");//從applivation作用域

      application.removeAttribute("");//從applivation作用域

      application.getRealPath("");//獲取資源物理位置

      application.getContext("");//獲取上下文,給頂一個資源路徑,獲得上下文對象

      application.getContextPath();//獲取上下文路徑,主要是獲取Web應用名

      application.getInitParameter("");//獲取指定的初始化參數

      application.getInitParameterNames();//獲取所有的初始化參數名

config

      config.getInitParameter("");//獲取指定的初始化參數

      config.getInitParameterNames();//獲取所有的初始化參數名

      config.getServletContext();//獲取應用application對象

      config.getServletName();//獲取Servlet名稱

exception

      exception.printStackTrace();//輸出異常棧信息

      exception.getMessage();//獲取異常信息

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章