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

Struts 2では、

<s:hidden>

タグを使用してHTMLの非表示フィールドを作成できます。

<s:hidden name="url" value="/"/>

次のHTMLコードとしてレンダリングされます。

<input type="hidden" name="url" value="/"/>

Struts 2 <s:hidden>の例

url隠し値を持つページ。フォームの送信後に隠し値を表示します。

1.アクション

package com.mkyong.common.action;

import com.opensymphony.xwork2.ActionSupport;

public class HiddenAction extends ActionSupport{

    private String url;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String execute() {
        return SUCCESS;
    }

}

2.表示ページ

Struts 2 ”

s:hidden

“タグを使用して、隠し値フィールドを作成します。

  • hidden.jsp **

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

<body>
<h1>Struts 2 - hidden value example</h1>

<s:form action="helloHidden" namespace="/">

    <h2>This page has a hidden value (view source):
    <s:hidden name="url" value="/"/></h2>

    <s:submit value="submit" name="submit"/>

</s:form>

</body>
</html>

  • welcome.jsp **

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>

<body>
<h1>Struts 2 - hidden value example</h1>

<h2>
  The hidden value :
  <s:property value="url"/>
</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="" namespace="/" extends="struts-default">
    <action name="hidden">
        <result>pages/hidden.jsp</result>
    </action>
    <action name="helloHidden" class="com.mkyong.common.action.HiddenAction">
        <result name="success">pages/welcome.jsp</result>
    </action>
   </package>

</struts>

リファレンス

ドキュメンテーション]

リンク://タグ/隠し値/[隠し値]リンク://tag/struts2/[struts2]