Struts 2 debug tag example

In Struts 2, the “debug” tag is a very useful debugging tag to output the content of the “Value Stack” and also the “Stack Context” details in the web page. In this tutorial, it shows the use of “debug” tag in JSP page.

1. Action

A simple Action class, with a “propertyInStack” property, show in value stack later.

DebugTagAction.java


package com.mkyong.common.action;

import com.opensymphony.xwork2.ActionSupport;
 
public class DebugTagAction extends ActionSupport{
	
	public String propertyInStack;

	public String getPropertyInStack() {
		return propertyInStack;
	}

	public void setPropertyInStack(String propertyInStack) {
		this.propertyInStack = propertyInStack;
	}

}

2. date tag example

A JSP page to show the use of “debug” tag to output the system’s “Value Stack” and “Stack Context“.

debug.jsp


<%@ taglib prefix="s" uri="/struts-tags" %>
 <html>
<head>
</head>
 
<body>
<h1>Struts 2 debug tag example</h1>

<s:debug />

</body>
</html>
The <s:debug /> will generate a text link named “debug“, you need to click on the text link to expand the debugging details.

3. struts.xml

Link it ~


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
 
<struts>
 	<constant name="struts.devMode" value="true" />
	<package name="default" namespace="/" extends="struts-default">
	
		<action name="debugTagAction" 
			class="com.mkyong.common.action.DebugTagAction" >
			<result name="success">pages/debug.jsp</result>
		</action>
		
	</package>
</struts>

4. Demo

http://localhost:8080/Struts2Example/debugTagAction.action

Output

Struts 2 debug tag example

Reference

  1. Struts 2 debug tag documentation

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
lilikaDeepak Jain Recent comment authors
newest oldest most voted
lilika
Guest
lilika

Vete a la mela chino malecon, preparame un arroz chaufa!

Deepak Jain
Guest
Deepak Jain

Really Good Information…