2007年10月16日火曜日

XML ベース JSP で使うアクションタグ

JSP ファイルは完全な XML 形式で記述できます。

XML 宣言
<?xml version="1.0" encoding="Shift_JIS"?>
を記述します。

ルート
<jsp:root>
xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" を指定します(JSP 2.0 の場合)。
jsp:root は必須です。

ディレクティブ(指令)
<jsp:directive.要素 属性 />

宣言部
<jsp:declaration></jsp:declaration>

スクリプトレット
<jsp:scriptlet></jsp:scriptlet>


<jsp:expression></jsp:expression>

テキスト
<jsp:text></jsp:text>

XML 予約文字の処理
XML 予約文字は CDATA セクションで囲みます。 

その他
<jsp:element>    要素の定義
<jsp:attribute>    属性の定義
<jsp:body>    属性に対するボディの定義
<jsp:output>    出力形式の定義
<jsp:forward>    転送
<jsp:include>    インクルード
<jsp:plugin>    アップレットなどの実行


<サンプル>
<?xml version="1.0" encoding="Shift_JIS"?>
<jsp:root
    xmlns:jsp="http://java.sun.com/JSP/Page"
    version="2.0">
<jsp:directive.page 
    contentType="text/html; charset=Shift_JIS" />
<jsp:text><&#33;[CDATA[
    <html>
    <body>
]]></jsp:text>
<jsp:declaration>int x;</jsp:declaration>
<jsp:scriptlet>x = 100;</jsp:scriptlet>
<jsp:text>The number is </jsp:text>
<jsp:expression>x</jsp:expression>
<jsp:text><&#33;[CDATA[
    </body>
    </html>
]]></jsp:text> 
</jsp:root>

<出力結果>
The number is 100

0 件のコメント: