Struts 2 <s:hidden> hidden value example

In Struts 2 , you can use the <s:hidden> tag to create a HTML hidden field.

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

It will render as the following HTML code.

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

Struts 2 <s:hidden> example

A page with a url hidden value, and display the hidden value after form is submitted.

1. Action

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.


<%@ taglib prefix="s" uri="/struts-tags" %>
<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" />


<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<h1>Struts 2 - hidden value example</h1>
  The hidden value :
  <s:property value="url"/>

3. struts.xml

Link all together ~

<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
   <constant name="struts.devMode" value="true" />
   <package name="" namespace="/" extends="struts-default">
	<action name="hidden">
	<action name="helloHidden" class="com.mkyong.common.action.HiddenAction">
		<result name="success">pages/welcome.jsp</result>

4. Demo


Struts2 hidden value example
Struts2 hidden value example


  1. Struts 2 hidden field documentation
Tags :

About the Author

Founder of and, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.