Struts2.2.1 Debug Tag Example
Posted on: January 5, 2011 at 12:00 AM
In this tutorial, We will discuss about the debug tag of struts2.2.1.

Struts2.2.1 Debug Tag Example

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.

The following Example will shows how to implement the Debug tag in the Struts2.2.1 --

First we create a JSP file named Debug.jsp as follows.ADS_TO_REPLACE_1

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

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>ADS_TO_REPLACE_2

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

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

<html>ADS_TO_REPLACE_3

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Struts2.2.1 Debug tag example</title>ADS_TO_REPLACE_4

</head>

<body>

<s:debug/>ADS_TO_REPLACE_5

</body>

</html>

The index.jsp file is as follows- This file only contains the hiperlink only.

<%@ page language="java" contentType="text/html; charset=UTF-8"ADS_TO_REPLACE_6

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>

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

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">ADS_TO_REPLACE_8

<title>Struts2.2.1 Debug tag example</title>

</head>

<body>ADS_TO_REPLACE_9

<a href="DebugTag.action">Debug Tag Example</a>

</body>

</html>

The Struts mapping file Struts.xml is as follows-ADS_TO_REPLACE_10

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"ADS_TO_REPLACE_11

"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.enable.DynamicMethodInvocation"ADS_TO_REPLACE_12

value="false" />

<constant name="struts.devMode" value="false" />

<constant name="struts.custom.i18n.resources"ADS_TO_REPLACE_13

value="ApplicationResources" />

<package name="default" namespace="/" extends="struts-default">

<action name="DebugTag" class="roseindia.DebugTag">ADS_TO_REPLACE_14

<result name="success">/Debug.jsp</result>

</action>

</package>ADS_TO_REPLACE_15

</struts>

The action class DebugTag.java is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;ADS_TO_REPLACE_16

public class DebugTag extends ActionSupport{

public String propertyInStack;

public String execute() throws Exception {ADS_TO_REPLACE_17

return SUCCESS;

}

public String getPropertyInStack()ADS_TO_REPLACE_18

{

return propertyInStack;

}ADS_TO_REPLACE_19

public void setPropertyInStack(String propertyInStack)

{

this.propertyInStack=propertyInStack;ADS_TO_REPLACE_20

}

}

This Program produces output on the basis of the Debug tag  evaluation, This  give the output as-

Output:-ADS_TO_REPLACE_21

On clicking the [Debug] output is as follows.ADS_TO_REPLACE_22

Download Select Source Code


Related Tags for Struts2.2.1 Debug Tag Example:

Advertisements

Ads

Ads

 
Advertisement null

Ads