Home Struts Struts Struts2.2.1 Tags Struts2.2.1 Debug Tag Example

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 Debug Tag Example
Posted on: January 5, 2011 at 12:00 AM
Advertisement
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.

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"%>

<!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>

<head>

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

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

</head>

<body>

<s:debug/>

</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"

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"%>

<html>

<head>

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

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

</head>

<body>

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

</body>

</html>

The Struts mapping file Struts.xml is as follows-

<?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.enable.DynamicMethodInvocation"

value="false" />

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

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

value="ApplicationResources" />

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

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

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

</action>

</package>

</struts>

The action class DebugTag.java is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class DebugTag extends ActionSupport{

public String propertyInStack;

public String execute() throws Exception {

return SUCCESS;

}

public String getPropertyInStack()

{

return propertyInStack;

}

public void setPropertyInStack(String propertyInStack)

{

this.propertyInStack=propertyInStack;

}

}

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

Output:-

On clicking the [Debug] output is as follows.

Download Select Source Code


Related Tags for Struts2.2.1 Debug Tag Example:


DMCA.com