SAStrutsでcommon.jspに機能を追加したいが特定のActionだけ適用させたくない場合
web.xmlでの設定がよくわからなかったので、
結局URLに特定の文字が含まれている場合、追加する部分を実行しないようにSimpleTagを作ってみた。
まずsample.SampleTagというJavaクラスを作ります。
ここではActionがSampleExcActionのものを除こうとしてみます。
public class SampleTag{ public static boolean exceptURL(String url) { String buf = S2Functions.url(url); return buf.matches("^.*/sampleExc/.*$"); } }
SimpleTagを/WEB-INF/tld/SampleTag.tldに作成します。
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd" version="2.0"> <tlib-version>2.0</tlib-version> <function> <name>sample</name> <function-class>sample.SampleTag</function-class> <function-signature> boolean exceptURL(java.lang.String) </function-signature> </function> </taglib>
web.xmlにSimpleTagを使う設定を記述します。
<jsp-config> <taglib> <taglib-uri>http://XXXX/SampleProject/Tag</taglib-uri> <taglib-location>/WEB-INF/tld/SampleTag.tld</taglib-location> </taglib> </jsp-config>
最後common.jspに
<%@taglib prefix="fn" uri="http://XXXX/SampleProject/Tag" %> <c:if test="${fn:exception(requestScope['javax.servlet.forward.request_uri']) == false}"> 〜ここに機能を書く〜 </c:if>
他にもっと何とかする方法があるんだろうけど、ひとまずこんなのしか思いつかなかった。