public abstract class WebUtils
extends java.lang.Object
修飾子と型 | フィールドと説明 |
---|---|
static java.lang.String | CONTENT_TYPE_CHARSET_PREFIX コンテンツ型文字列の文字セット句の接頭辞: "; charset ="。 |
static java.lang.String | DEFAULT_CHARACTER_ENCODING サーブレットの仕様に従って、 request.getCharacterEncoding が null を返すときに使用するデフォルトの文字エンコーディング。 |
static java.lang.String | DEFAULT_WEB_APP_ROOT_KEY デフォルトの Web アプリのルートキー: "webapp.root"。 |
static java.lang.String | ERROR_EXCEPTION_ATTRIBUTE エラーページ例外の標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | ERROR_EXCEPTION_TYPE_ATTRIBUTE エラーページ例外型の標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | ERROR_MESSAGE_ATTRIBUTE エラーページメッセージの標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | ERROR_REQUEST_URI_ATTRIBUTE エラーページリクエスト URI の標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | ERROR_SERVLET_NAME_ATTRIBUTE エラーページサーブレット名の標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | ERROR_STATUS_CODE_ATTRIBUTE エラーページステータスコードの標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | FORWARD_CONTEXT_PATH_ATTRIBUTE フォワードコンテキストパスの標準 Servlet 2.4+ 仕様リクエスト属性。 |
static java.lang.String | FORWARD_PATH_INFO_ATTRIBUTE フォワードパス情報の標準 Servlet 2.4+ 仕様リクエスト属性。 |
static java.lang.String | FORWARD_QUERY_STRING_ATTRIBUTE 前方クエリ文字列の標準 Servlet 2.4+ 仕様リクエスト属性。 |
static java.lang.String | FORWARD_REQUEST_URI_ATTRIBUTE 転送リクエスト URI の標準 Servlet 2.4+ 仕様リクエスト属性。 |
static java.lang.String | FORWARD_SERVLET_PATH_ATTRIBUTE フォワードサーブレットパスの標準 Servlet 2.4+ 仕様リクエスト属性。 |
static java.lang.String | HTML_ESCAPE_CONTEXT_PARAM サーブレットコンテキストレベルの HTML エスケープパラメーター(つまり |
static java.lang.String | INCLUDE_CONTEXT_PATH_ATTRIBUTE インクルードコンテキストパスの標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | INCLUDE_PATH_INFO_ATTRIBUTE インクルードパス情報の標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | INCLUDE_QUERY_STRING_ATTRIBUTE インクルードクエリ文字列の標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | INCLUDE_REQUEST_URI_ATTRIBUTE インクルードリクエスト URI の標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | INCLUDE_SERVLET_PATH_ATTRIBUTE インクルードサーブレットパスの標準 Servlet 2.3+ 仕様リクエスト属性。 |
static java.lang.String | RESPONSE_ENCODED_HTML_ESCAPE_CONTEXT_PARAM サーブレットコンテキストレベルでの HTML エスケープパラメーターのレスポンスエンコーディングの使用(つまり |
static java.lang.String | SESSION_MUTEX_ATTRIBUTE mutex セッション属性のキー。 |
static java.lang.String[] | SUBMIT_IMAGE_SUFFIXES イメージボタンの場合は名前のサフィックス。 |
static java.lang.String | TEMP_DIR_CONTEXT_ATTRIBUTE 型 java.io.File の、現在の Web アプリケーションの一時ディレクトリを指定する標準サーブレット仕様コンテキスト属性。 |
static java.lang.String | WEB_APP_ROOT_KEY_PARAM サーブレットコンテキストレベルの Web アプリのルートキーパラメーター(つまり |
コンストラクターと説明 |
---|
WebUtils() |
修飾子と型 | メソッドと説明 |
---|---|
static void | clearErrorRequestAttributes(HttpServletRequestEE request) サーブレット仕様のエラー属性を、Servlet 2.3 仕様で定義されているキー javax.servlet.error.status_code 、javax.servlet.error.exception_type 、javax.servlet.error.message 、javax.servlet.error.exception 、javax.servlet.error.request_uri 、javax.servlet.error.servlet_name の HttpServletRequest EE 属性としてクリアします。 |
static void | exposeErrorRequestAttributes(HttpServletRequestEE request, java.lang.Throwable ex, java.lang.String servletName) サーブレットコンテナーのエラーページの解決方法 javax.servlet.error.status_code 、javax.servlet.error.exception_type 、javax.servlet.error.message 、javax.servlet.error.exception 、javax.servlet.error.request_uri 、javax.servlet.error.servlet_name ではなく直接レンダリングされるエラーページについて、Servlet 2.3 仕様で定義されたキーにある HttpServletRequest EE 属性としてサーブレット仕様のエラー属性を公開します。 |
static java.lang.String | findParameterValue(java.util.Map<java.lang.String,?> parameters, java.lang.String name) 指定されたリクエストパラメーターから名前付きパラメーターを取得します。 |
static java.lang.String | findParameterValue(ServletRequestEE request, java.lang.String name) 指定されたリクエストパラメーターから名前付きパラメーターを取得します。 |
static CookieEE | getCookie(HttpServletRequestEE request, java.lang.String name) 指定された名前の最初の Cookie を取得します。 |
static java.lang.Boolean | getDefaultHtmlEscape(ServletContextEE servletContext) デフォルトの HTML エスケープが Web アプリケーションで有効かどうかを返します。 |
static <T> T | getNativeRequest(ServletRequestEE request, java.lang.Class<T> requiredType) 指定された型の適切なリクエストオブジェクトを返します(可能な場合)。必要に応じて、指定されたリクエストをアンラップします。 |
static <T> T | getNativeResponse(ServletResponseEE response, java.lang.Class<T> requiredType) 指定された型の適切なレスポンスオブジェクトを返します(可能な場合)。必要に応じて、指定されたレスポンスをラップします。 |
static java.util.Map<java.lang.String,java.lang.Object> | getParametersStartingWith(ServletRequestEE request, java.lang.String prefix) 指定されたプレフィックスを持つすべてのパラメーターを含むマップを返します。 |
static java.lang.String | getRealPath(ServletContextEE servletContext, java.lang.String path) サーブレットコンテナーによって提供される、Web アプリケーション内の指定されたパスの実際のパスを返します。 |
static java.lang.Object | getRequiredSessionAttribute(HttpServletRequestEE request, java.lang.String name) 指定された名前のセッション属性について、指定されたリクエストを確認してください。 |
static java.lang.Boolean | getResponseEncodedHtmlEscape(ServletContextEE servletContext) HTML が文字をエスケープするときにレスポンスエンコーディングを使用する必要があるかどうかを返します。つまり、UTF- * エンコーディングで XML マークアップの重要な文字のみをエスケープします。 |
static java.lang.Object | getSessionAttribute(HttpServletRequestEE request, java.lang.String name) 指定された名前のセッション属性について、指定されたリクエストを確認してください。 |
static java.lang.String | getSessionId(HttpServletRequestEE request) 指定されたリクエストのセッション ID を確認します(ある場合)。 |
static java.lang.Object | getSessionMutex(HttpSessionEE session) 指定されたセッションで利用可能な最良のミューテックスを返します。つまり、指定されたセッションで同期するオブジェクトです。 |
static java.io.File | getTempDir(ServletContextEE servletContext) サーブレットコンテナーによって提供される、現在の Web アプリケーションの一時ディレクトリを返します。 |
static boolean | hasSubmitParameter(ServletRequestEE request, java.lang.String name) 特定の入力 type="submit" パラメーターがリクエストで送信されたかどうかを、ボタン(直接名前で)またはイメージ(名前 + ".x" または名前 + ".y" )で送信したかどうかを確認します。 |
static boolean | isIncludeRequest(ServletRequestEE request) 指定されたリクエストがインクルードリクエストであるかどうか、つまり外部から入ってくるトップレベルの HTTP リクエストではないかどうかを判断します。 |
static boolean | isSameOrigin(HttpRequest request) Origin 、Host 、Forwarded 、X-Forwarded-Proto 、X-Forwarded-Host 、X-Forwarded-Port ヘッダーに基づいて、リクエストが同一生成元のものであるかどうかを確認します。 |
static boolean | isValidOrigin(HttpRequest request, java.util.Collection<java.lang.String> allowedOrigins) 指定されたリクエストの起点を、許可された起点のリストと照合します。 |
static MultiValueMap<java.lang.String,java.lang.String> | parseMatrixVariables(java.lang.String matrixVariables) 与えられた文字列をマトリックス変数で解析します。 |
static void | removeWebAppRootSystemProperty(ServletContextEE servletContext) Web アプリのルートディレクトリを指すシステムプロパティを削除します。 |
static void | setSessionAttribute(HttpServletRequestEE request, java.lang.String name, java.lang.Object value) 指定された名前のセッション属性を指定された値に設定します。 |
static void | setWebAppRootSystemProperty(ServletContextEE servletContext) システムプロパティを Web アプリケーションのルートディレクトリに設定します。 |
public static final java.lang.String INCLUDE_REQUEST_URI_ATTRIBUTE
RequestDispatcher
を介して含まれている場合、現在のリソースには元のリクエストが表示されます。独自のリクエスト URI がリクエスト属性として公開されます。
public static final java.lang.String INCLUDE_CONTEXT_PATH_ATTRIBUTE
RequestDispatcher
を介して含まれている場合、現在のリソースには元のコンテキストパスが表示されます。独自のコンテキストパスがリクエスト属性として公開されます。
public static final java.lang.String INCLUDE_SERVLET_PATH_ATTRIBUTE
RequestDispatcher
を介して含まれている場合、現在のリソースには元のサーブレットパスが表示されます。独自のサーブレットパスがリクエスト属性として公開されます。
public static final java.lang.String INCLUDE_PATH_INFO_ATTRIBUTE
RequestDispatcher
を介して含まれている場合、現在のリソースには元のパス情報が表示されます。独自のパス情報がリクエスト属性として公開されます。
public static final java.lang.String INCLUDE_QUERY_STRING_ATTRIBUTE
RequestDispatcher
を介して含まれている場合、現在のリソースには元のクエリ文字列が表示されます。独自のクエリ文字列はリクエスト属性として公開されます。
public static final java.lang.String FORWARD_REQUEST_URI_ATTRIBUTE
RequestDispatcher 経由でに転送された場合、現在のリソースには独自のリクエスト URI が表示されます。元のリクエスト URI はリクエスト属性として公開されます。
public static final java.lang.String FORWARD_CONTEXT_PATH_ATTRIBUTE
RequestDispatcher を介してに転送された場合、現在のリソースには独自のコンテキストパスが表示されます。元のコンテキストパスはリクエスト属性として公開されます。
public static final java.lang.String FORWARD_SERVLET_PATH_ATTRIBUTE
RequestDispatcher 経由でに転送された場合、現在のリソースには独自のサーブレットパスが表示されます。元のサーブレットパスは、リクエスト属性として公開されます。
public static final java.lang.String FORWARD_PATH_INFO_ATTRIBUTE
RequestDispatcher を介してに転送された場合、現在のリソースには独自のパスが表示されます。元のパス情報はリクエスト属性として公開されます。
public static final java.lang.String FORWARD_QUERY_STRING_ATTRIBUTE
RequestDispatcher 経由でに転送された場合、現在のリソースには独自のクエリ文字列が表示されます。元のクエリ文字列はリクエスト属性として公開されます。
public static final java.lang.String ERROR_STATUS_CODE_ATTRIBUTE
エラーページとしてマークされている JSP に公開されるため、サーブレットコンテナーのエラーページ解決メカニズムを介してではなく、JSP に直接転送します。
public static final java.lang.String ERROR_EXCEPTION_TYPE_ATTRIBUTE
エラーページとしてマークされている JSP に公開されるため、サーブレットコンテナーのエラーページ解決メカニズムを介してではなく、JSP に直接転送します。
public static final java.lang.String ERROR_MESSAGE_ATTRIBUTE
エラーページとしてマークされている JSP に公開されるため、サーブレットコンテナーのエラーページ解決メカニズムを介してではなく、JSP に直接転送します。
public static final java.lang.String ERROR_EXCEPTION_ATTRIBUTE
エラーページとしてマークされている JSP に公開されるため、サーブレットコンテナーのエラーページ解決メカニズムを介してではなく、JSP に直接転送します。
public static final java.lang.String ERROR_REQUEST_URI_ATTRIBUTE
エラーページとしてマークされている JSP に公開されるため、サーブレットコンテナーのエラーページ解決メカニズムを介してではなく、JSP に直接転送します。
public static final java.lang.String ERROR_SERVLET_NAME_ATTRIBUTE
エラーページとしてマークされている JSP に公開されるため、サーブレットコンテナーのエラーページ解決メカニズムを介してではなく、JSP に直接転送します。
public static final java.lang.String CONTENT_TYPE_CHARSET_PREFIX
public static final java.lang.String DEFAULT_CHARACTER_ENCODING
request.getCharacterEncoding
が null
を返すときに使用するデフォルトの文字エンコーディング。public static final java.lang.String TEMP_DIR_CONTEXT_ATTRIBUTE
java.io.File
の、現在の Web アプリケーションの一時ディレクトリを指定する標準サーブレット仕様コンテキスト属性。public static final java.lang.String HTML_ESCAPE_CONTEXT_PARAM
web.xml
のコンテキストパラメーター): "defaultHtmlEscape"。public static final java.lang.String RESPONSE_ENCODED_HTML_ESCAPE_CONTEXT_PARAM
web.xml
のコンテキストパラメーター) に対するレスポンスエンコーディングの使用: "responseEncodedHtmlEscape"。public static final java.lang.String WEB_APP_ROOT_KEY_PARAM
web.xml
のコンテキストパラメーター): "webAppRootKey"。public static final java.lang.String DEFAULT_WEB_APP_ROOT_KEY
public static final java.lang.String[] SUBMIT_IMAGE_SUFFIXES
public static final java.lang.String SESSION_MUTEX_ATTRIBUTE
public static void setWebAppRootSystemProperty(ServletContextEE servletContext) throws java.lang.IllegalStateException
web.xml
の "webAppRootKey" コンテキストパラメーターで定義できます。デフォルトは "webapp.root" です。 ログファイルの場所内の log4j の "${key}" 構文など、System.getProperty
値での置換をサポートするツールに使用できます。
servletContext
- Web アプリケーションのサーブレットコンテキスト java.lang.IllegalStateException
- システムプロパティがすでに設定されている場合、または WAR ファイルが展開されていない場合 WEB_APP_ROOT_KEY_PARAM
, DEFAULT_WEB_APP_ROOT_KEY
, WebAppRootListener
public static void removeWebAppRootSystemProperty(ServletContextEE servletContext)
servletContext
- Web アプリケーションのサーブレットコンテキスト setWebAppRootSystemProperty(javax.servlet.ServletContext)
@Nullable public static java.lang.Boolean getDefaultHtmlEscape(@Nullable ServletContextEE servletContext)
web.xml
の "defaultHtmlEscape" コンテキストパラメーターの値 (存在する場合) を返します。このメソッドは、パラメーターがまったく指定されていないことと指定された実際のブール値を区別し、グローバルレベルで設定がない場合にコンテキスト固有のデフォルトを設定できるようにします。
servletContext
- Web アプリケーションのサーブレットコンテキスト null
= 明示的なデフォルトなし)@Nullable public static java.lang.Boolean getResponseEncodedHtmlEscape(@Nullable ServletContextEE servletContext)
web.xml
の "responseEncodedHtmlEscape" コンテキストパラメーターの値 (存在する場合) を持つ Web アプリケーションで有効になります。このメソッドは、パラメーターがまったく指定されていないことと指定された実際のブール値を区別し、グローバルレベルで設定がない場合にコンテキスト固有のデフォルトを設定できるようにします。
servletContext
- Web アプリケーションのサーブレットコンテキスト null
= 明示的なデフォルトなし)public static java.io.File getTempDir(ServletContextEE servletContext)
servletContext
- Web アプリケーションのサーブレットコンテキスト public static java.lang.String getRealPath(ServletContextEE servletContext, java.lang.String path) throws java.io.FileNotFoundException
パスがスラッシュで始まっていない場合はスラッシュを付加し、パスをリソースに解決できない場合は FileNotFoundException をスローします(ServletContext の getRealPath
は null を返します)。
servletContext
- Web アプリケーションのサーブレットコンテキスト path
- Web アプリケーション内のパス java.io.FileNotFoundException
- パスをリソースに解決できない場合 ServletContext.getRealPath(java.lang.String)
EE@Nullable public static java.lang.String getSessionId(HttpServletRequestEE request)
request
- 現在の HTTP リクエスト null
@Nullable public static java.lang.Object getSessionAttribute(HttpServletRequestEE request, java.lang.String name)
request
- 現在の HTTP リクエスト name
- セッション属性の名前 null
public static java.lang.Object getRequiredSessionAttribute(HttpServletRequestEE request, java.lang.String name) throws java.lang.IllegalStateException
request
- 現在の HTTP リクエスト name
- セッション属性の名前 null
java.lang.IllegalStateException
- セッション属性が見つからなかった場合 public static void setSessionAttribute(HttpServletRequestEE request, java.lang.String name, @Nullable java.lang.Object value)
request
- 現在の HTTP リクエスト name
- セッション属性の名前 value
- セッション属性の値 public static java.lang.Object getSessionMutex(HttpSessionEE session)
利用可能な場合はセッションミューテックス属性を返します。通常、これは HttpSessionMutexListener を web.xml
で定義する必要があることを意味します。mutex 属性が見つからない場合は、HttpSession 自体にフォールバックします。
セッションミューテックスは、セッションのライフタイム全体を通じて同じオブジェクトであることが保証されており、SESSION_MUTEX_ATTRIBUTE
定数で定義されたキーで使用できます。これは、現在のセッションのロックを同期するための安全な参照として機能します。
多くの場合、HttpSession 参照自体も、同じアクティブな論理セッションに対する常に同じオブジェクト参照になるため、安全なミューテックスです。ただし、これは異なるサーブレットコンテナー間では保証されません。唯一の 100% 安全な方法は、セッションミューテックスです。
session
- ミューテックスを見つける HttpSessionnull
)SESSION_MUTEX_ATTRIBUTE
, HttpSessionMutexListener
@Nullable public static <T> T getNativeRequest(ServletRequestEE request, @Nullable java.lang.Class<T> requiredType)
request
- イントロスペクトするサーブレットリクエスト requiredType
- 目的の型のリクエストオブジェクト null
@Nullable public static <T> T getNativeResponse(ServletResponseEE response, @Nullable java.lang.Class<T> requiredType)
response
- イントロスペクトに対するサーブレットのレスポンス requiredType
- 希望する型のレスポンスオブジェクト null
public static boolean isIncludeRequest(ServletRequestEE request)
"javax.servlet.include.request_uri" リクエスト属性の存在を確認します。インクルードリクエストにのみ存在するリクエスト属性をチェックできます。
request
- 現在のサーブレットリクエスト public static void exposeErrorRequestAttributes(HttpServletRequestEE request, java.lang.Throwable ex, @Nullable java.lang.String servletName)
javax.servlet.error.status_code
、javax.servlet.error.exception_type
、javax.servlet.error.message
、javax.servlet.error.exception
、javax.servlet.error.request_uri
、javax.servlet.error.servlet_name
ではなく直接レンダリングされるエラーページについて、Servlet 2.3 仕様で定義されたキーにある HttpServletRequest
EE 属性としてサーブレット仕様のエラー属性を公開します。以前に明示的に公開された属性値を考慮するために、すでに存在する場合は値をオーバーライドしません。
デフォルトでステータスコード 200 を公開します。異なるステータスコードを公開するために、"javax.servlet.error.status_code" 属性を明示的に(前または後に)設定します。
request
- 現在のサーブレットリクエスト ex
- 発生した例外 servletName
- 問題のあるサーブレットの名前 public static void clearErrorRequestAttributes(HttpServletRequestEE request)
javax.servlet.error.status_code
、javax.servlet.error.exception_type
、javax.servlet.error.message
、javax.servlet.error.exception
、javax.servlet.error.request_uri
、javax.servlet.error.servlet_name
の HttpServletRequest
EE 属性としてクリアします。request
- 現在のサーブレットリクエスト @Nullable public static CookieEE getCookie(HttpServletRequestEE request, java.lang.String name)
request
- 現在のサーブレットリクエスト name
- クッキー名 null
public static boolean hasSubmitParameter(ServletRequestEE request, java.lang.String name)
request
- 現在の HTTP リクエスト name
- パラメーターの名前 SUBMIT_IMAGE_SUFFIXES
@Nullable public static java.lang.String findParameterValue(ServletRequestEE request, java.lang.String name)
ルックアップアルゴリズムの説明については、findParameterValue(java.util.Map, String)
を参照してください。
request
- 現在の HTTP リクエスト name
- リクエストパラメーターの論理名 null
@Nullable public static java.lang.String findParameterValue(java.util.Map<java.lang.String,?> parameters, java.lang.String name)
このメソッドは、次のアルゴリズムを使用してパラメーター値を取得しようとします。
parameters
- 利用可能なパラメーターマップ name
- リクエストパラメーターの論理名 null
public static java.util.Map<java.lang.String,java.lang.Object> getParametersStartingWith(ServletRequestEE request, @Nullable java.lang.String prefix)
例: "spring _"、"spring_param1"、"spring_param2" の接頭辞を使用すると、"param1" と "param2" をキーとするマップが作成されます。
request
- パラメーターを探す HTTP リクエスト prefix
- パラメーター名の始まり (これが null または空の文字列の場合、すべてのパラメーターが一致します)ServletRequest.getParameterNames()
EE, ServletRequest.getParameterValues(java.lang.String)
EE, ServletRequest.getParameterMap()
EEpublic static MultiValueMap<java.lang.String,java.lang.String> parseMatrixVariables(java.lang.String matrixVariables)
"q1=a;q1=b;q2=a,b,c"
のようになります。結果のマップには、キー "q1"
および "q2"
が含まれ、それぞれ値 ["a","b"]
および ["a","b","c"]
が含まれます。matrixVariables
- 解析されていないマトリックス変数文字列 null
)public static boolean isValidOrigin(HttpRequest request, java.util.Collection<java.lang.String> allowedOrigins)
注意 : 5.1 以降、このメソッドは、クライアントが発信したアドレスを指定する "Forwarded"
および "X-Forwarded-*"
ヘッダーを無視します。ForwardedHeaderFilter
を使用して、このようなヘッダーを抽出して使用するか、破棄することを検討してください。
true
、それ以外の場合は false
public static boolean isSameOrigin(HttpRequest request)
Origin
、Host
、Forwarded
、X-Forwarded-Proto
、X-Forwarded-Host
、X-Forwarded-Port
ヘッダーに基づいて、リクエストが同一生成元のものであるかどうかを確認します。 注意 : 5.1 以降、このメソッドは、クライアントが発信したアドレスを指定する "Forwarded"
および "X-Forwarded-*"
ヘッダーを無視します。ForwardedHeaderFilter
を使用して、このようなヘッダーを抽出して使用するか、破棄することを検討してください。
true
、クロスオリジンリクエストの場合は false