ダウンロードする – リンク://wp-content/uploads/2010/07/Struts2-A-Tag-Example.zip[Struts2-A-Tag-Example.zip]
Struts 2 ”
a
“タグはHTML ”
<a>
“タグのレンダリングに使用されます。 URLを作成して「
a
」タグに埋め込むには、常に「
<s:url>
」タグを使用することをお勧めします。例えば、
<s:url value="http://www.google.com" var="googleURL"/>
<s:a href="%{googleURL}">Google</s:a>
このチュートリアルでは、Struts 2 ”
a
“タグを使用する3つの方法を示します。
1.アクション
リクエストを転送するActionクラス。
package com.mkyong.common.action;
import com.opensymphony.xwork2.ActionSupport;
public class ATagAction extends ActionSupport{
public String execute() {
return SUCCESS;
}
}
2.タグの例
さまざまな方法でURLをレンダリングするための ”
a
“タグの使用を示すJSPページ。
-
a.jsp **
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
</head>
<body>
<h1>Struts 2 a tag example</h1>
<ol>
<li>
<s:url value="/" var="mkyongURL"/>
<s:a href="%{mkyongURL}">J2EE web development tutorials</s:a>
</li>
<li>
<s:a href="http://www.google.com">Google search engine</s:a>
</li>
<li>
<s:url action="aTagAction.action" var="aURL"/>
<s:a href="%{aURL}">aTagAction</s:a>
</li>
</ol>
</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="aTagAction"
class="com.mkyong.common.action.aTagAction" >
<result name="success">pages/a.jsp</result>
</action>
</package>
</struts>
4.デモ
-
出力**
image =//wp-content/uploads/2010/07/Struts2-A-Tag-Example.jpg[Struts 2のタグ例、title = “Struts2-A-Tag-Example”、width = 640、height = 255]
-
HTMLソースの出力**
<html> <head> </head> <body> <h1>Struts 2 a tag example</h1> <ol> <li> <a href="/">J2EE web development tutorials</a> </li> <li> <a href="http://www.google.com">Google search engine</a> </li> <li> <a href="/Struts2Example/aTagAction.action">aTagAction</a> </li> </ol> </body> </html>