• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us

Struts 2 Hidden Tag Example

December 14, 2013 //  by Krishna Srinivasan

Struts 2 Hidden Tag is helpful for passing the hidden values from one page to another page. In the latest web development there is very less need for using this kind of tags for the functionality. If your framework is not handling the values by default, you need to define the hidden fields and then maintain the values across the pages. These values are not displayed to the user, but hidden from the screen.

1. Action Class

package javabeat.net.struts2;

public class Struts2UITagsAction{
	private String pageId;

	public String getPageId() {
		return pageId;
	}

	public void setPageId(String pageId) {
		this.pageId = pageId;
	}

	public String execute(){
		return "success";
	}
}

2. Hidden Tag Example

Hidden.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
</head>
<body>
	<h2>JavaBeat - Struts 2 Hidden Field Demo</h2>
	<s:form action="HiddenDemo">
		<s:hidden name="pageId" value="0" />
		<s:submit label="Submit" />
	</s:form>

</body>
</html>

Result.jsp

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<body>
	<h2>JavaBeat - Struts 2 Hidden Tag Demo</h2>
	<h4>
		Page Id :	<s:property value="pageId" /><br>
	</h4>
</body>
</html>

3. Struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="uitagsdemo" extends="struts-default">
	<action name="HiddenDemo" class="javabeat.net.struts2.Struts2UITagsAction" >
		<result name="success">Result.jsp</result>
	</action>
</package>
</struts>

4. Hidden Tag Demo

If you access the application using URL http://localhost:8080/Struts2App/HiddenDemo, you would see the following output.

struts2 hidden tag example input screen

struts2 hidden tag example output screen

Category: JavaTag: Struts 2 Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « How To Set Tomcat JVM Heap Size in Eclipse?
Next Post: Struts 2 TextArea Tag Example »

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

How to Initialize an Array in Java

Introduction to Java Server Faces (JSF)

Introduction to Java 6.0 New Features, Part–1

Java 6.0 Features Part – 2 : Pluggable Annotation Processing API

Introduction to Java Server Faces(JSF) HTML Tags

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact