Pages Navigation Menu

Coding is much easier than you think

Struts 2 <s:hidden> example

Struts 2 <s:hidden> example


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


<s:hidden name="hiddenValue" value="simplecodestuffs" />

It will render as the following HTML code.

<input type="hidden" name="hiddenValue" value="simplecodestuffs" />


Struts 2 <s:hidden> example

A page with a url hidden value, and display the hidden value after form is submitted.
** UPDATE: Struts 2 Complete tutorial now available here.

1. Folder Structure :


Folder Structurehidden


2. Action class


package com.simplecode.action;

import com.opensymphony.xwork2.ActionSupport;

public class HiddenAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String hiddenValue;

	public String getHiddenValue() {
		return hiddenValue;

	public void setHiddenValue(String hiddenValue) {
		this.hiddenValue = hiddenValue;

	public String execute() {
		return SUCCESS;



3. JSP View page

Struts 2 €œs:hidden€ tag to create a hidden value field.



<%@taglib uri="/struts-tags" prefix="s"%>
	<h3>Struts 2 - &lt;s:hidden&gt; tag example</h3>
	This page has a hidden value (view source):
	<s:form action="Hidden">

			<s:hidden name="hiddenValue" value="simplecodestuffs" />
			<s:submit key="project.submit" name="submit" />



<%@ taglib prefix="s" uri="/struts-tags"%>
<title>Welcome Page</title>

	<h3>Struts 2 - &lt;s:hidden&gt; tag example</h3>

	The hidden value :
	<s:property value="hiddenValue" />



4. struts.xml


<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

	<constant name="struts.custom.i18n.resources" value="project" />
	<package name="default" extends="struts-default" namespace="/jsp">
		<action name="Hiddenjsp">
		<action name="Hidden" class="com.simplecode.action.HiddenAction">
			<result name="success">/jsp/success.jsp</result>
			<result name="input">/jsp/hidden.jsp</result>


5. Demo



Output :
s:hidden box




  1. Struts 2 hidden field documentation


About Mohaideen Jamil

Am currently working as a Struts 2 Developer in a reputed IT Organisations. I can help you with teaching Core java and Struts 2. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.