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.

 



It will render as the following HTML code.


 

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

 

HiddenAction.java

 

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.

hidden.jsp

 

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



Hidden


	

Struts 2 - <s:hidden> tag example

This page has a hidden value (view source):

 

success.jsp
 

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



Welcome Page



	

Struts 2 - <s:hidden> tag example

The hidden value :

 

4. struts.xml

 





	
	
		
			/jsp/hidden.jsp
		
		
			/jsp/success.jsp
			/jsp/hidden.jsp
		
	

 

5. Demo

 
http://localhost:8089/Struts2_hidden/jsp/Hiddenjsp
 

s:hidden

 
Output :
 
s:hidden box

 

 

Reference

  1. Struts 2 hidden field documentation

 

2 Comments

  1. Hello,
    If I have multiple submit buttons (with call to different action methods) or multiple forms and I want to pass a same hidden value to all, do I need to use multiple tags or Can I use a common tag for all buttons??