Struts2 + OGNL式でリクエストパス関係文字列を取得

OGNL式では”#request”と書くと”HttpServletRequest”オブジェクトを参照出来ますが、これを利用してリクエスト周りのパス文字列を取得するメモ

<%-- 例)リクエストURLが"http://localhost/ContextName/hoge/?param=abc"の場合、"/ContextName/hoge/"が返る --%>
<s:property value="#request.get('javax.servlet.forward.request_uri')"/>

<%-- 例)リクエストURLが"http://localhost/ContextName/hoge/?param=abc"の場合、"/ContextName"が返る --%>
<s:property value="#request.get('javax.servlet.forward.context_path')"/>

<%-- 例)リクエストURLが"http://localhost/ContextName/hoge/?param=abc"の場合、"/hoge/"が返る --%>
<s:property value="#request.get('javax.servlet.forward.servlet_path')"/>

<%-- 例)リクエストURLが"http://localhost/ContextName/hoge/?param=abc"の場合、""が返る --%>
<s:property value="#request.get('javax.servlet.forward.path_info')"/>

<%-- 例)リクエストURLが"http://localhost/ContextName/hoge/?param=abc"の場合、"param=abc"が返る --%>
<s:property value="#request.get('javax.servlet.forward.query_string')"/>

<%-- 例)サーブレットパスにより分岐 --%>
<s:if test="-1 == (#request.get('javax.servlet.forward.servlet_path')).indexOf(\"checkStr\")">
	:
</s:if>
<s:else>
	:
</s:else>

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>