Struts 2 Debug Tag Example
In Struts 2, the “debug” tag is used to output the content of the “Value Stack” and Stack Context details in the web page.
** UPDATE: Struts 2 Complete tutorial now available here.
1. Jsp debug tag example
A JSP page to output the system’s “Value Stack” and “Stack Context” using debug tag.
debug.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib uri="/struts-tags" prefix="s"%> <html> <head> <title>Debug tag</title> </head> <body> <h3>Debug tag</h3> <s:debug /> </body> </html>
2. Action class
A Action class, with a field named actionProperty” property, show in value stack in jsp.
DebugTag.java
package com.simplecode.action; import com.opensymphony.xwork2.Action; public class DebugTag implements Action { public String actionProperty; public String getActionProperty() { return actionProperty; } public void setActionProperty(String actionProperty) { this.actionProperty = actionProperty; } }
3. struts.xml
<?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" extends="struts-default"> <action name="debugTagAction" class="com.simplecode.action.DebugTag"> <result name="success">/debug.jsp</result> </action> </package> </struts>
4. Demo
http://localhost:8089/Debug/debugTagAction.action
Output
The <s:debug /> will generate a text link named “debug“, On clicking this link, it expands to show the debugging details.
|