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 :
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
Output :
|
Reference
- Struts 2 hidden field documentation
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??
Common tag is enough