Struts 2 <s:hidden> hidden value example
Published: June 20, 2010 , Updated: June 18, 2010 , Author: mkyong
Download It – Struts2-Hidden-Example.zip
In Struts 2 , you can use the <s:hidden> tag to create a HTML hidden field.
<s:hidden name="url" value="http://www.mkyong.com" />It will render as the following HTML code.
<input type="hidden" name="url" value="http://www.mkyong.com" />Struts 2 <s:hidden> example
A page with a url hidden value, and display the hidden value after form is submitted.
1. Action
HiddenAction.java
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. View page
Struts 2 “s:hidden” tag to create a hidden value field.
hidden.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> </head> <body> <h1>Struts 2 - hidden value example</h1> <s:form action="helloHidden" namespace="/"> <h4>This page has a hidden value (view source): <s:hidden name="url" value="http://www.mkyong.com" /></h4> <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> <h4> The hidden value : <s:property value="url"/> </h4> </body> </html>
3. struts.xml
Link all together ~
<?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>
4. Demo
http://localhost:8080/Struts2Example/hidden.action


Reference
Note : You can find more similar articles at - Struts 2.x Tutorials







[...] 2 <s:textfield> textbox example.Password example Struts 2 <s:password> password example.Hidden value example Struts 2 <s:hidden> hidden value example.Textarea example Struts 2 <s:textarea> [...]