public class JstlView extends InternalResourceView
InternalResourceView
の特殊化。Spring のロケールと MessageSource
を使用して、JSTL のフォーマットとメッセージタグのロケールとリソースバンドルを指定する JSTL 固有のリクエスト属性を公開します。
InternalResourceViewResolver
の一般的な使用箇所は、DispatcherServlet コンテキスト定義の観点から、次のようになります。
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="messages"/> </bean>ハンドラーから返されるすべてのビュー名は、明示的な JSTL サポートを有効にするためにこのビュークラスを使用して、JSP リソースに変換されます (例: "myView" -> "/WEB-INF/jsp/myView.jsp")。
指定された MessageSource は、クラスパス内の "messages.properties" などのファイルからメッセージをロードします。これは、JSTL fmt タグ(メッセージなど)が使用する JSTL ローカライゼーションコンテキストとしてビューに自動的に公開されます。より洗練されたものにするために、標準の ResourceBundleMessageSource の代わりに Spring の ReloadableResourceBundleMessageSource を使用することを検討してください。もちろん、他の Spring コンポーネントは同じ MessageSource を共有できます。
これは、主に InternalResourceView
自体の JSTL 依存関係を回避するための別個のクラスです。JSTL は、J2EE 1.4 まで標準 J2EE の一部ではなかったため、クラスパスで JSTL API jar が使用可能であると想定することはできません。
ヒント: JSTL 式(c:out
値式など)内でアプリケーションコンテキスト内のすべての Spring Bean にアクセスできるようにするには、AbstractView.setExposeContextBeansAsAttributes(boolean)
フラグを "true" に設定します。これにより、JSP 2.0 ページのプレーンな ${...}
式でそのようなすべての Bean にアクセスできるようになります。
DEFAULT_CONTENT_TYPE
logger
PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE
コンストラクターと説明 |
---|
JstlView() Bean として使用するコンストラクター。 |
JstlView(StringSE url) 指定された URL で新しい JstlView を作成します。 |
JstlView(StringSE url, MessageSource messageSource) 指定された URL で新しい JstlView を作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
protected void | exposeHelpers(HttpServletRequestEE request) Spring のロケールおよび MessageSource の JSTL LocalizationContext を公開します。 |
protected void | initServletContext(ServletContextEE servletContext) JSTL の javax.servlet.jsp.jstl.fmt.localizationContext コンテキストパラメーターを認識する JSTL 対応 MessageSource で MessageSource をラップします。 |
getRequestDispatcher, isContextRequired, prepareForRendering, renderMergedOutputModel, setAlwaysInclude, setPreventDispatchLoop, useInclude
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, setServletContext
getApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, waitSE, waitSE, waitSE
public JstlView()
public JstlView(StringSE url)
url
- 転送先の URLpublic JstlView(StringSE url, MessageSource messageSource)
url
- 転送先の URLmessageSource
- JSTL タグに公開する MessageSource (JSTL の javax.servlet.jsp.jstl.fmt.localizationContext
コンテキストパラメーターを認識する JSTL 対応 MessageSource でラップされます)JstlUtils.getJstlAwareMessageSource(javax.servlet.ServletContext, org.springframework.context.MessageSource)
protected void initServletContext(ServletContextEE servletContext)
javax.servlet.jsp.jstl.fmt.localizationContext
コンテキストパラメーターを認識する JSTL 対応 MessageSource で MessageSource をラップします。WebApplicationObjectSupport
の initServletContext
servletContext
- このアプリケーションオブジェクトが実行される ServletContext (非 null
)JstlUtils.getJstlAwareMessageSource(javax.servlet.ServletContext, org.springframework.context.MessageSource)
protected void exposeHelpers(HttpServletRequestEE request) throws ExceptionSE
InternalResourceView
の exposeHelpers
request
- 現在の HTTP リクエスト ExceptionSE
- 属性の追加中に致命的なエラーが発生した場合 JstlUtils.exposeLocalizationContext(javax.servlet.http.HttpServletRequest, org.springframework.context.MessageSource)