ホームページ  >  記事  >  Java  >  JSP の 9 つの組み込みオブジェクトの機能を紹介および説明します。

JSP の 9 つの組み込みオブジェクトの機能を紹介および説明します。

PHPz
PHPzオリジナル
2024-01-31 16:03:06948ブラウズ

JSP の 9 つの組み込みオブジェクトの機能を紹介および説明します。

#JSP の 9 つの組み込みオブジェクトの概要と機能

1. request

request オブジェクトは、クライアントによって送信されたリクエスト (リクエスト パラメータ、リクエスト ヘッダーなど、クライアントによって送信されたすべての情報を含む)これは javax.servlet.http.HttpServletRequest オブジェクトです。

関数:

    リクエストパラメータの取得: request.getParameter(文字列名)
  • リクエストヘッダの取得: request.getHeader(文字列名) )
  • リクエスト メソッドの取得: request.getMethod()
  • リクエスト URI の取得: request.getRequestURI()
  • リクエスト URL の取得: request.getRequestURL()
  • リクエスト プロトコルの取得: request.getProtocol()
  • リクエストの文字エンコーディングの取得: request.getCharacterEncoding()
  • リクエスト コンテンツ タイプの取得: request.getContentType()
  • リクエストのコンテンツ長の取得: request.getContentLength()
  • リクエストされた ServletPath の取得: request.getServletPath()
  • リクエストされた ContextPath の取得: request.getContextPath()
  • リクエストされたセッションを取得します: request.getSession()
  • リクエストされた Cookie を取得します: request.getCookies()
  • リクエストされたロケールを取得します: request.getLocale()

2. 応答

応答オブジェクトは、応答ヘッダーや応答本文など、クライアントに送信されるすべてのデータを含む、サーバーのクライアントへの応答を表します。これは javax.servlet.http.HttpServletResponse オブジェクトです。

関数:

    応答ステータス コードを設定します:response.setStatus(int sc)
  • 応答ヘッダーを設定します:response.setHeader (文字列名、文字列値)
  • 応答文字エンコーディングを設定します:response.setCharacterEncoding(String charset)
  • 応答コンテンツ タイプを設定します:response.setContentType(String contentType)
  • 応答出力ストリームの取得:response.getOutputStream()
  • 応答 PrintWriter の取得:response.getWriter()

3. session

session オブジェクトは、クライアントとサーバー間のクライアント セッションを表します。これには、ユーザーのログイン情報、ショッピング カート情報など、クライアントとサーバー間の対話中に生成されるすべての情報が含まれます。これは javax.servlet.http.HttpSession オブジェクトです。

関数:

    セッション ID の取得: session.getId()
  • セッションの作成時刻の取得: session.getCreationTime( )
  • セッションの最終アクセス時刻を取得します: session.getLastAccessedTime()
  • セッションの最大非アクティブ時間を取得します: session.getMaxInactiveInterval()
  • 最大非アクティブ時間を設定しますセッションの: session .setMaxInactiveInterval(int interval)
  • セッション内の属性を取得します: session.getAttribute(String name)
  • セッション内の属性を設定します: session.setAttribute(String name,オブジェクト値)
  • セッション内の属性の削除: session.removeAttribute(文字列名)
  • セッションの無効化: session.invalidate()

4. application

アプリケーション オブジェクトは、すべての ServletContext オブジェクトを含む Web アプリケーション全体を表します。これは javax.servlet.ServletContext オブジェクトです。

関数:

    ServletContext の取得: application.getServletContext()
  • Web アプリケーションの名前の取得: application.getServletContext( ).getServletContextName()
  • Web アプリケーションのバージョンを取得します: application.getServletContext().getMajorVersion() "." application.getServletContext().getMinorVersion()
  • Web アプリケーションの ContextPath を取得しますWeb アプリケーション: application.getServletContext().getContextPath()
  • Web アプリケーションのサーブレットを取得します: application.getServletContext().getServlets()
  • Web アプリケーションのフィルターを取得します: application.getServletContext().getFilters()
  • Web アプリケーションのリスナーを取得します: application.getServletContext().getListeners()
  • Web アプリケーションのリソースを取得します: application.getServletContext( ).getResource(String path)
  • Web アプリケーションのリソース パスを取得します: application.getServletContext().getResourcePaths(String path)
  • Web アプリケーションの MimeType を取得します: application.getServletContext ().getMimeType(String file)

5. out

out オブジェクトは、java.io である JSP ページの出力ストリームを表します。 .PrintWriter オブジェクト。

関数:

    コンテンツを JSP ページに出力します: out.print(Object obj)
  • 改行文字を JSP ページに出力します。 JSP ページ: out .println()

6. page

page オブジェクトは、現在の JSP ページ (javax.servlet.jsp) を表します。 PageContext オブジェクト。 #########効果:######
  • 現在の JSP ページの ServletContext を取得します: page.getServletContext()
  • 現在の JSP ページのリクエストを取得します: page.getRequest()
  • 現在の JSP ページのリクエストを取得します: page.getRequest()
  • 現在の JSP ページ: page .getResponse()
  • 現在の JSP ページのセッションを取得: page.getSession()
  • 現在の JSP ページのアプリケーションを取得: page.getServletContext() .getServletContext()
  • 現在の JSP ページの JspWriter を取得します: page.getOut()
  • 現在の JSP ページの ServletConfig を取得します: page.getServletConfig()
  • 現在の JSP ページの構成を取得します: page.getConfig()
  • 現在の JSP ページの ErrorPage を取得します: page.getErrorPage()
  • 現在の JSP ページの例外を取得します: page .getException()
  • 現在の JSP ページの IsErrorPage を取得します: page.isErrorPage ()
  • 現在の JSP ページの IsPage を取得します: page.isPage()
  • 現在の JSP ページの IsELIgnored を取得する: page.isELIgnored()
現在の JSP ページの IsScriptingIgnored を取得する: page.isScriptingIgnored()

7. 構成

#config オブジェクトは、現在の JSP ページの構成情報 (javax.servlet.ServletConfig オブジェクト) を表します。

関数:
  • 現在の JSP ページの ServletName を取得します: config.getServletName()
  • 現在の JSP の ContextPath を取得しますページ: config.getServletContext().getContextPath()
  • 現在の JSP ページの InitParameter を取得します: config.getInitParameter(String name)
現在の JSP ページの InitParameterNames を取得します: config. getInitParameterNames()

8. pageContext

pageContext オブジェクトは、現在の JSP ページのコンテキスト (javax.servlet.jsp.PageContext オブジェクト) を表します。 。

関数:
  • 現在の JSP ページの ServletContext を取得します: pageContext.getServletContext()
  • 現在の JSP のリクエストを取得しますページ: pageContext.getRequest()
  • 現在の JSP ページのレスポンスを取得する: pageContext.getResponse()
  • 現在の JSP ページのセッションを取得する: pageContext.getSession()
  • 現在の JSP ページ アプリケーションのセッションを取得します: pageContext.getServletContext().getServletContext()
  • 現在の JSP ページの JspWriter を取得します: pageContext.getOut()
  • 現在の JSP ページの ServletConfig: pageContext.getServletConfig()
  • 現在の JSP ページの Config を取得する: pageContext.getConfig()
  • 現在の JSP ページの ErrorPage を取得する: pageContext.getErrorPage ()
  • 現在の JSP ページの例外を取得します: pageContext.getException( )
  • 現在の JSP ページの IsErrorPage を取得します: pageContext.isErrorPage()
  • 現在の JSP ページの IsPage: pageContext.isPage()
  • 現在の JSP ページの IsELIgnored を取得: pageContext.isELIgnored()
現在の JSP ページの IsScriptingIgnored を取得: pageContext.isScriptingIgnored ()

9.例外

例外オブジェクトの表現 現在の JSP ページで発生する例外は、java.lang.Throwable オブジェクトです。

関数:
  • 現在の JSP ページで発生する例外を取得します:Exception.getMessage()
発生した例外を取得します現在の JSP ページのスタック トレース:例外.printStackTrace()######

以上がJSP の 9 つの組み込みオブジェクトの機能を紹介および説明します。の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。