public class RedirectView extends AbstractUrlBasedView implements SmartView
isEligibleProperty(String, Object)
メソッドをオーバーライドすることで変更できます。 このビューの URL は、HTTP リダイレクト URL であることが想定されています。つまり、HttpServletResponse の sendRedirect
メソッドに適しています。これは、HTTP 1.0 フラグがオンの場合、または HTTP 303 コードの送信を介してリダイレクトを実際に行うものです -HTTP 1.0 互換の場合フラグはオフです。
"contextRelative" フラグのデフォルト値はオフですが、ほとんどの場合、これを true に設定するとよいことに注意してください。フラグがオフの場合、"/" で始まる URL は Web サーバーのルートに対して相対的であると見なされ、フラグがオンの場合、Web アプリケーションのルートに対して相対的であると見なされます。ほとんどの Web アプリケーションは、コンテキストパスが実際に何であるかを知らないか、気にしないため、このフラグを true に設定し、Web アプリケーションのルートに対して相対的であると見なされるパスを送信する方がはるかに適切です。
ポートレット環境でこのリダイレクトビューを使用する場合の注意 : コントローラーがポートレット sendRedirect
制約を遵守していることを確認してください。
setContextRelative(boolean)
, setHttp10Compatible(boolean)
, setExposeModelAttributes(boolean)
, HttpServletResponse.sendRedirect(java.lang.String)
EEDEFAULT_CONTENT_TYPE
logger
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
コンストラクターと説明 |
---|
RedirectView() Bean として使用するコンストラクター。 |
RedirectView(StringSE url) 指定された URL で新しい RedirectView を作成します。 |
RedirectView(StringSE url, boolean contextRelative) 指定された URL で新しい RedirectView を作成します。 |
RedirectView(StringSE url, boolean contextRelative, boolean http10Compatible) 指定された URL で新しい RedirectView を作成します。 |
RedirectView(StringSE url, boolean contextRelative, boolean http10Compatible, boolean exposeModelAttributes) 指定された URL で新しい RedirectView を作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
protected void | appendCurrentQueryParams(StringBuilderSE targetUrl, HttpServletRequestEE request) 現在のリクエストのクエリ文字列をターゲットリダイレクト URL に追加します。 |
protected void | appendQueryProperties(StringBuilderSE targetUrl, MapSE<StringSE, ObjectSE> model, StringSE encodingScheme) リダイレクト URL にクエリプロパティを追加します。 |
protected StringSE | createTargetUrl(MapSE<StringSE, ObjectSE> model, HttpServletRequestEE request) 最初にリダイレクト文字列が URI テンプレートであるかどうかを確認してターゲット URL を作成し、指定されたモデルでそれを展開してから、オプションでクエリ文字列パラメーターとして単純型モデル属性を追加します。 |
StringSE[] | getHosts() 設定されたアプリケーションホストを返します。 |
protected HttpStatus | getHttp11StatusCode(HttpServletRequestEE request, HttpServletResponseEE response, StringSE targetUrl) HTTP 1.1 互換リクエストに使用するステータスコードを決定します。 |
protected boolean | isContextRequired() ApplicationContext は、RedirectView には厳密には必要ありません。 |
protected boolean | isEligibleProperty(StringSE key, ObjectSE value) 指定されたモデル要素をクエリプロパティとして公開するかどうかを決定します。 |
protected boolean | isEligibleValue(ObjectSE value) 指定されたモデル要素の値が公開の対象かどうかを判断します。 |
boolean | isPropagateQueryProperties() 現在の URL のクエリパラメーターを伝達するかどうか。 |
boolean | isRedirectView() このビューがリダイレクトを実行することを示す "true" を返します。 |
protected boolean | isRemoteHost(StringSE targetUrl) 指定された targetUrl に「外部」システムのホストがあるかどうか。その場合、 HttpServletResponse.encodeRedirectURL(java.lang.String) EE は適用されません。 |
protected MapSE<StringSE, ObjectSE> | queryProperties(MapSE<StringSE, ObjectSE> model) appendQueryProperties(java.lang.StringBuilder, java.util.Map<java.lang.String, java.lang.Object>, java.lang.String) によって文字列化、URL エンコード、フォーマットされるクエリ文字列の名前と値のペアを決定します。 |
protected void | renderMergedOutputModel(MapSE<StringSE, ObjectSE> model, HttpServletRequestEE request, HttpServletResponseEE response) モデルをリクエストパラメーターに変換し、指定された URL にリダイレクトします。 |
protected StringBuilderSE | replaceUriTemplateVariables(StringSE targetUrl, MapSE<StringSE, ObjectSE> model, MapSE<StringSE, StringSE> currentUriVariables, StringSE encodingScheme) ターゲット URL の URI テンプレート変数を、現在のリクエストからのエンコードされたモデル属性または URI 変数に置き換えます。 |
protected void | sendRedirect(HttpServletRequestEE request, HttpServletResponseEE response, StringSE targetUrl, boolean http10Compatible) HTTP クライアントにリダイレクトを送り返します。 |
void | setContextRelative(boolean contextRelative) スラッシュ("/")で始まる特定の URL を、現在の ServletContext を基準にして解釈するかどうかを設定します。 |
void | setEncodingScheme(StringSE encodingScheme) このビューのコード化スキームを設定します。 |
void | setExpandUriTemplateVariables(boolean expandUriTemplateVariables) リダイレクト URL を URI テンプレートとして扱うかどうか。 |
void | setExposeModelAttributes(boolean exposeModelAttributes) モデル属性を HTTP クエリパラメーターとして公開する必要があるかどうかを示す exposeModelAttributes フラグを設定します。 |
void | setHosts(StringSE... hosts) アプリケーションに関連付けられた 1 つ以上のホストを構成します。 |
void | setHttp10Compatible(boolean http10Compatible) HTTP 1.0 クライアントとの互換性を維持するかどうかを設定します。 |
void | setPropagateQueryParams(boolean propagateQueryParams) true に設定すると、現在の URL のクエリ文字列が追加され、リダイレクトされた URL に伝達されます。 |
void | setStatusCode(HttpStatus statusCode) このビューのステータスコードを設定します。 |
protected StringSE | updateTargetUrl(StringSE targetUrl, MapSE<StringSE, ObjectSE> model, HttpServletRequestEE request, HttpServletResponseEE response) 登録されている RequestDataValueProcessor がある場合は検索して、リダイレクトターゲット URL を更新できるようにします。 |
protected StringSE | urlEncode(StringSE input, StringSE encodingScheme) 指定されたエンコードスキームを使用して、指定された入力文字列を URL エンコードします。 |
afterPropertiesSet, checkResource, getUrl, isUrlRequired, setUrl, toString
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, writeToResponse
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, setServletContext
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
getContentType, render
public RedirectView()
public RedirectView(StringSE url)
指定された URL は、現在の ServletContext に対してではなく、Web サーバーに対するものと見なされます。
url
- リダイレクト先の URLRedirectView(String, boolean)
public RedirectView(StringSE url, boolean contextRelative)
url
- リダイレクト先の URLcontextRelative
- 指定された URL を現在の ServletContext を基準にして解釈するかどうか public RedirectView(StringSE url, boolean contextRelative, boolean http10Compatible)
url
- リダイレクト先の URLcontextRelative
- 指定された URL を現在の ServletContext を基準にして解釈するかどうか http10Compatible
- HTTP 1.0 クライアントとの互換性を維持するかどうか public RedirectView(StringSE url, boolean contextRelative, boolean http10Compatible, boolean exposeModelAttributes)
url
- リダイレクト先の URLcontextRelative
- 指定された URL を現在の ServletContext を基準にして解釈するかどうか http10Compatible
- HTTP 1.0 クライアントとの互換性を維持するかどうか exposeModelAttributes
- モデル属性をクエリパラメーターとして公開するかどうか public void setContextRelative(boolean contextRelative)
デフォルトは「false」: スラッシュで始まる URL は、絶対的なものとして解釈されます。つまり、そのまま解釈されます。"true" の場合、このような場合、コンテキストパスが URL の前に付加されます。
public void setHttp10Compatible(boolean http10Compatible)
デフォルトの実装では、これにより HTTP ステータスコード 302 が強制されます。つまり、HttpServletResponse.sendRedirect
に委譲されます。これをオフにすると、HTTP 1.1 クライアントの正しいコードである HTTP ステータスコード 303 が送信されますが、HTTP 1.0 クライアントでは認識されません。
多くの HTTP 1.1 クライアントは、302 を 303 のように扱い、違いはありません。ただし、POST リクエストの後でリダイレクトする場合、一部のクライアントは 303 に依存します。このようなシナリオでは、このフラグをオフにしてください。
public void setExposeModelAttributes(boolean exposeModelAttributes)
exposeModelAttributes
フラグを設定します。 デフォルトは true
です。
public void setEncodingScheme(StringSE encodingScheme)
デフォルトはリクエストのコード化スキームです(特に指定されていない場合は ISO-8859-1 です)。
public void setStatusCode(HttpStatus statusCode)
デフォルトでは、http10Compatible
フラグの値に応じて、302/303 を送信します。
public void setExpandUriTemplateVariables(boolean expandUriTemplateVariables)
false
に設定します。 デフォルトは true
です。
public void setPropagateQueryParams(boolean propagateQueryParams)
true
に設定すると、現在の URL のクエリ文字列が追加され、リダイレクトされた URL に伝達されます。 デフォルトは false
です。
public boolean isPropagateQueryProperties()
public void setHosts(@Nullable StringSE... hosts)
実際、このプロパティは、ホストがあり、そのホストが既知のホストとしてリストされていない URL に対して、HttpServletResponse.encodeRedirectURL(java.lang.String)
EE を介したエンコーディングをオフにする方法を提供します。
設定されていない場合(デフォルト)、すべての URL がレスポンスを通じてエンコードされます。
hosts
- 1 つ以上のアプリケーションホスト public boolean isRedirectView()
SmartView
の isRedirectView
protected boolean isContextRequired()
WebApplicationObjectSupport
の isContextRequired
ApplicationObjectSupport.getApplicationContext()
, ApplicationObjectSupport.getMessageSourceAccessor()
, WebApplicationObjectSupport.getWebApplicationContext()
, WebApplicationObjectSupport.getServletContext()
, WebApplicationObjectSupport.getTempDir()
protected void renderMergedOutputModel(MapSE<StringSE,ObjectSE> model, HttpServletRequestEE request, HttpServletResponseEE response) throws IOExceptionSE
AbstractView
の renderMergedOutputModel
model
- 静的な属性よりも動的な値が優先される、結合された出力マップ(非 null
)request
- 現在の HTTP リクエスト response
- 現在の HTTP レスポンス IOExceptionSE
appendQueryProperties(java.lang.StringBuilder, java.util.Map<java.lang.String, java.lang.Object>, java.lang.String)
, sendRedirect(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, boolean)
protected final StringSE createTargetUrl(MapSE<StringSE,ObjectSE> model, HttpServletRequestEE request) throws UnsupportedEncodingExceptionSE
protected StringBuilderSE replaceUriTemplateVariables(StringSE targetUrl, MapSE<StringSE,ObjectSE> model, MapSE<StringSE,StringSE> currentUriVariables, StringSE encodingScheme) throws UnsupportedEncodingExceptionSE
targetUrl
- リダイレクト URLmodel
- モデル属性を含むマップ currentUriVariables
- 使用する現在のリクエスト URI 変数 encodingScheme
- 使用するコード化スキーム UnsupportedEncodingExceptionSE
- 文字列のエンコードに失敗した場合 protected void appendCurrentQueryParams(StringBuilderSE targetUrl, HttpServletRequestEE request)
targetUrl
- プロパティを追加する StringBuilderrequest
- 現在のリクエスト protected void appendQueryProperties(StringBuilderSE targetUrl, MapSE<StringSE,ObjectSE> model, StringSE encodingScheme) throws UnsupportedEncodingExceptionSE
targetUrl
- プロパティを追加する StringBuildermodel
- モデル属性を含むマップ encodingScheme
- 使用するコード化スキーム UnsupportedEncodingExceptionSE
- 文字列のエンコードに失敗した場合 queryProperties(java.util.Map<java.lang.String, java.lang.Object>)
protected MapSE<StringSE,ObjectSE> queryProperties(MapSE<StringSE,ObjectSE> model)
appendQueryProperties(java.lang.StringBuilder, java.util.Map<java.lang.String, java.lang.Object>, java.lang.String)
によって文字列化、URL エンコード、フォーマットされるクエリ文字列の名前と値のペアを決定します。 この実装では、デフォルトで文字列、プリミティブ、プリミティブラッパーのみを受け入れ、各要素の isEligibleProperty(String, Object)
をチェックすることでモデルをフィルタリングします。
model
- 元のモデルマップ isEligibleProperty(String, Object)
protected boolean isEligibleProperty(StringSE key, @Nullable ObjectSE value)
デフォルトの実装では、文字列とプリミティブが適格であると見なされ、対応する要素を持つ配列とコレクション / イテラブルも考慮されます。これはサブクラスでオーバーライドできます。
key
- モデル要素のキー value
- モデル要素の値 protected boolean isEligibleValue(@Nullable ObjectSE value)
BeanUtils.isSimpleValueType(java.lang.Class<?>)
によると、デフォルトの実装では、プリミティブ、文字列、数値、日付、URI、URL などが適格と見なされます。これはサブクラスでオーバーライドできます。
value
- モデル要素の値 BeanUtils.isSimpleValueType(java.lang.Class<?>)
protected StringSE urlEncode(StringSE input, StringSE encodingScheme) throws UnsupportedEncodingExceptionSE
デフォルトの実装では URLEncoder.encode(input, enc)
を使用します。
input
- エンコードされていない入力文字列 encodingScheme
- エンコーディングスキーム UnsupportedEncodingExceptionSE
- JDK URLEncoder によってスローされた場合 URLEncoder.encode(String, String)
SEprotected StringSE updateTargetUrl(StringSE targetUrl, MapSE<StringSE,ObjectSE> model, HttpServletRequestEE request, HttpServletResponseEE response)
RequestDataValueProcessor
がある場合は検索して、リダイレクトターゲット URL を更新できるようにします。targetUrl
- 指定されたリダイレクト URLprotected void sendRedirect(HttpServletRequestEE request, HttpServletResponseEE response, StringSE targetUrl, boolean http10Compatible) throws IOExceptionSE
request
- 現在の HTTP リクエスト (リクエストメソッドに反応することができます)response
- 現在の HTTP レスポンス (レスポンスヘッダーを送信するため)targetUrl
- リダイレクトするターゲット URLhttp10Compatible
- HTTP 1.0 クライアントとの互換性を維持するかどうか IOExceptionSE
- レスポンスメソッドによってスローされた場合 protected boolean isRemoteHost(StringSE targetUrl)
HttpServletResponse.encodeRedirectURL(java.lang.String)
EE は適用されません。setHosts(String[])
プロパティが構成され、ターゲット URL に一致しないホストがある場合、このメソッドは true
を返します。targetUrl
- ターゲットのリダイレクト URLtrue
ターゲット URL にはリモートホストがあり、false
(URL にホストがない場合、「ホスト」プロパティが構成されていない場合)。protected HttpStatus getHttp11StatusCode(HttpServletRequestEE request, HttpServletResponseEE response, StringSE targetUrl)
デフォルトの実装は、設定されている場合は statusCode
プロパティ、または View.RESPONSE_STATUS_ATTRIBUTE
属性の値を返します。どちらも設定されていない場合、デフォルトは HttpStatus.SEE_OTHER
(303) です。
request
- インスペクション依頼 response
- サーブレットレスポンス targetUrl
- ターゲット URL