ダウンロードする – リンク://wp-content/uploads/2010/07/Struts2-Include-Tag-Example.zip[Struts2-Include-Tag-Example.zip]

Struts 2 ”

include

“タグはJSPまたはHTMLページを現在のページに直接インクルードするために使用されます。以下の ”

include

“タグのデモの例を参照してください。

1.アクション

前方タスクのみを実行する単純なActionクラス。

package com.mkyong.common.action;

import com.opensymphony.xwork2.ActionSupport;

public class IncludeTagAction extends ActionSupport{

    public String execute() throws Exception {

        return SUCCESS;
    }
}

2. includeタグの例

現在のページ ”

include.jsp

“に ”

mkyong.jsp

“ページを含めるための

include

“タグの使用方法を示しています。

  • include.jsp **

<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>

<body>
<h1>Struts 2 include tag example</h1>

<s:include value="/pages/mkyong.jsp"></s:include>

</body>
</html>

  • mkyong.jsp **

<html>
<head>
</head>

<body>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-2836379775501347"
     data-ad-slot="8821506761"
     data-ad-format="auto"
     data-ad-region="mkyongregion"></ins>
<script>
(adsbygoogle = window.adsbygoogle ||[]).push({});
</script><h2>Message from mkyong.jsp</h2>

</body>
</html>

3. struts.xml

リンク〜

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true"/>
    <package name="default" namespace="/" extends="struts-default">

        <action name="includeTagAction"
            class="com.mkyong.common.action.IncludeTagAction" >
            <result name="success">pages/include.jsp</result>
        </action>

    </package>
</struts>

4.デモ

  • 出力**

image =//wp-content/uploads/2010/07/Struts2-Include-Tag-Example.jpg[Struts 2はタグの例を含む、title = “Struts2-Include-Tag-Example”、width = 639、height = 265]

リファレンス

ドキュメンテーション]