blob: 456669f92956e04c51a1f8079f164b7c82caeddd [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="Date-Revision-yyyymmdd" content="20140918"/>
<meta http-equiv="Content-Language" content="en"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Debugging Struts</title>
<link href="//,400,600,700,400italic,600italic,700italic" rel="stylesheet" type="text/css">
<link href="//" rel="stylesheet">
<link href="/css/main.css" rel="stylesheet">
<link href="/css/custom.css" rel="stylesheet">
<link href="/highlighter/github-theme.css" rel="stylesheet">
<script src="//"></script>
<script type="text/javascript" src="/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="/js/community.js"></script>
<a href="" class="github-ribbon">
<img style="position: absolute; right: 0; border: 0;" src="" alt="Fork me on GitHub">
<div role="navigation" class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" data-toggle="collapse" data-target="#struts-menu" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<a href="/index.html" class="navbar-brand logo"><img src="/img/struts-logo.svg"></a>
<div id="struts-menu" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a data-toggle="dropdown" href="#" class="dropdown-toggle">
Home<b class="caret"></b>
<ul class="dropdown-menu">
<li><a href="/index.html">Welcome</a></li>
<li><a href="/download.cgi">Download</a></li>
<li><a href="/releases.html">Releases</a></li>
<li><a href="/announce-2021.html">Announcements</a></li>
<li><a href="">License</a></li>
<li><a href="">Thanks!</a></li>
<li><a href="">Sponsorship</a></li>
<li class="dropdown">
<a data-toggle="dropdown" href="#" class="dropdown-toggle">
Support<b class="caret"></b>
<ul class="dropdown-menu">
<li><a href="/mail.html">User Mailing List</a></li>
<li><a href="">Issue Tracker</a></li>
<li><a href="/security.html">Reporting Security Issues</a></li>
<li class="divider"></li>
<li><a href="">Version Notes</a></li>
<li><a href="">Security Bulletins</a></li>
<li class="divider"></li>
<li><a href="/maven/project-info.html">Maven Project Info</a></li>
<li><a href="/maven/struts2-core/dependencies.html">Struts Core Dependencies</a></li>
<li><a href="/maven/struts2-plugins/modules.html">Plugin Dependencies</a></li>
<li class="dropdown">
<a data-toggle="dropdown" href="#" class="dropdown-toggle">
Documentation<b class="caret"></b>
<ul class="dropdown-menu">
<li><a href="/birdseye.html">Birds Eye</a></li>
<li><a href="/primer.html">Key Technologies</a></li>
<li><a href="/kickstart.html">Kickstart FAQ</a></li>
<li><a href="">Wiki</a></li>
<li class="divider"></li>
<li><a href="/getting-started/">Getting Started</a></li>
<li><a href="/security/">Security Guide</a></li>
<li><a href="/core-developers/">Core Developers Guide</a></li>
<li><a href="/tag-developers/">Tag Developers Guide</a></li>
<li><a href="/maven-archetypes/">Maven Archetypes</a></li>
<li><a href="/plugins/">Plugins</a></li>
<li><a href="/maven/struts2-core/apidocs/index.html">Struts Core API</a></li>
<li><a href="/tag-developers/tag-reference.html">Tag reference</a></li>
<li><a href="">FAQs</a></li>
<li><a href="">Plugin registry</a></li>
<li class="dropdown">
<a data-toggle="dropdown" href="#" class="dropdown-toggle">
Contributing<b class="caret"></b>
<ul class="dropdown-menu">
<li><a href="/youatstruts.html">You at Struts</a></li>
<li><a href="/helping.html">How to Help FAQ</a></li>
<li><a href="/dev-mail.html">Development Lists</a></li>
<li><a href="/contributors/">Contributors Guide</a></li>
<li class="divider"></li>
<li><a href="/submitting-patches.html">Submitting patches</a></li>
<li><a href="/builds.html">Source Code and Builds</a></li>
<li><a href="/coding-standards.html">Coding standards</a></li>
<li><a href="">Contributors Guide</a></li>
<li class="divider"></li>
<li><a href="/release-guidelines.html">Release Guidelines</a></li>
<li><a href="/bylaws.html">PMC Charter</a></li>
<li><a href="/volunteers.html">Volunteers</a></li>
<li><a href="">Source Repository</a></li>
<li><a href="/updating-website.html">Updating the website</a></li>
<li class="apache"><a href=""><img src="/img/apache.png"></a></li>
<article class="container">
<section class="col-md-12">
<a class="edit-on-gh" href="" title="Edit this page on GitHub">Edit on GitHub</a>
<a href="index.html" title="back to Getting started"><< back to Getting started</a>
<h1 class="no_toc" id="debugging-struts">Debugging Struts</h1>
<ul id="markdown-toc">
<li><a href="#introduction" id="markdown-toc-introduction">Introduction</a></li>
<li><a href="#configuration-plugin" id="markdown-toc-configuration-plugin">Configuration Plugin</a></li>
<li><a href="#using-the-debugging-interceptor" id="markdown-toc-using-the-debugging-interceptor">Using the Debugging Interceptor</a></li>
<li><a href="#struts-2-logging" id="markdown-toc-struts-2-logging">Struts 2 Logging</a></li>
<li><a href="#summary" id="markdown-toc-summary">Summary</a></li>
<p>The example code for this tutorial, <strong>debugging-struts</strong>, is available for checkout at <a href="">struts-examples</a>.</p>
<h2 id="introduction">Introduction</h2>
<p>During development of a Struts 2 web application you may want to view the information being managed by the Struts 2 framework.
This tutorial will cover two tools you can use to see how Struts 2 views your web application. One tool is the Struts 2
configuration plugin and the other is the debugging interceptor. This article also discusses how to set the log level
to see more or fewer log messages.</p>
<p>The Struts 2 <a href="">user mailing list</a> is an excellent place to get help. If you are having
a problem getting the tutorial example applications to work search the Struts 2 mailing list. If you don’t find an answer
to your problem, post a question on the mailing list.</p>
<h2 id="configuration-plugin">Configuration Plugin</h2>
<p>The Struts 2 config browser plugin provides details about the configuration the Struts 2 framework is using to run your
application. To use the plugin your application needs to have the struts2-config-browser-plugin-x.x.x.x.jar in your
application’s class path. The config-browser-plugin jar is part of the Struts 2 download and is also available in the Maven
<p>To use the plugin in your application, just call index.action in namespace <code class="highlighter-rouge">config-browser</code>. For example you could have
the following link on your admin page (or just anywhere during your development).</p>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">'&lt;s:url action="index" namespace="config-browser" /&gt;'</span><span class="nt">&gt;</span>Launch the configuration browser<span class="nt">&lt;/a&gt;</span>
<p>In the example application, there is a link to the configuration browser on the index.jsp page.</p>
<p>Clicking on the link for the configuration browser will cause the Struts 2 framework to return this page to your browser.</p>
<p><img src="attachments/att17137672_debuging-struts-1.png" alt="debuging-struts-1.png" /></p>
<p>You can click on an action link to see the configuration for that action. For example clicking on the register action
link results in this.</p>
<p><img src="attachments/att17137673_debuging-struts-2.png" alt="debuging-struts-2.png" /></p>
<p>You may then click on one of the tabs (Results, Exception Mappings, Interceptors, Properties, Validators) to get more
information about how the Struts 2 framework has configured that specific action.</p>
<p>On the left side of the page is the config browser plugin menu. Clicking on constants will render a view that lists all
the Struts 2 constants and their properties for your application. Clicking on beans shows the beans Struts 2 is managing.
Clicking on Jars shows the jars your application is using.</p>
<h2 id="using-the-debugging-interceptor">Using the Debugging Interceptor</h2>
<p>If you have set <code class="highlighter-rouge">devMode</code> to true (in the example application see <code class="highlighter-rouge">struts.xml</code>) then one of the interceptors that is
activated when Struts 2 processes an action is the DebuggingInterceptor. The DebuggingInterceptor looks for a query
string appended to the action URL with a name of debug and a value of xml, console, command, or browser.</p>
<p>If the <code class="highlighter-rouge">DebuggingInterceptor</code> finds that query string then it will halt further execution of the action and instead return
to the browser debugging information. The format of the returned information depends on the value of the debug query parameter.
See <a href="../core-developers/debugging-interceptor.html">DebuggingInterceptor</a> for more detail.</p>
<p>In the example application on the index.jsp is a link for displaying debugging information. This link includes the query
string <code class="highlighter-rouge">debug=browser</code>. If you click on this link you’ll see a table with columns that can be expanded and collapsed.
The table contains the various objects and their state being managed by the Struts 2 framework.</p>
<p><img src="attachments/att17137674_debuging-struts-3.png" alt="debuging-struts-3.png" /></p>
<p>Note that to enable the correct display and interaction of the expand/collapse links on the debugging information web page
you need to include the <code class="highlighter-rouge">s:head</code> tag in your JSP’s head section (see index.jsp in the example application) and also include
the Struts 2 dojo plugin in your application’s class path. The Struts 2 dojo plugin is available as part of the Struts 2
download and from the Maven repository.</p>
<h2 id="struts-2-logging">Struts 2 Logging</h2>
<p>The Struts 2 framework will write to a log a great deal of information if you’ve configured the log properties to log at
the debug level. In the example application, view <code class="highlighter-rouge">log4j2.xml</code>. The two major packages involved in the Struts 2 framework,
<code class="highlighter-rouge">com.opensymphony</code> and <code class="highlighter-rouge">org.apache.struts2</code>, are configured to write debug and above log messages. When you run the application
view the standard out for your Servlet container to see all the information written to the log. Please check <a href="../core-developers/logging.html">Logging</a>
page for other options.</p>
<h2 id="summary">Summary</h2>
<p>Using the configuration browser plugin and the debugging interceptor can assist you in trouble shooting a problem with
a Struts 2 web application. These tools should only be used in development.</p>
<p>Prior to creating your war file for deployment to production you should change <code class="highlighter-rouge">devMode</code> to false and remove the debugging
links. You may also want to adjust the level of logging in your log properties file to a higher level (info or warn) to reduce
the number of log messages.</p>
<td>Return to <a href="exception-handling.html">Exception handling</a></td>
<td>onward to <a href="form-tags.html">Form tags</a></td>
<footer class="container">
<div class="col-md-12">
Copyright &copy; 2000-2018 <a href="">The Apache Software Foundation </a>.
All Rights Reserved.
<div class="col-md-12">
Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project logos are
trademarks of The Apache Software Foundation.
<div class="col-md-12">Logo and website design donated by <a href="">SoftwareMill</a>.</div>
<script>!function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (!d.getElementById(id)) {
js = d.createElement(s); = id;
js.src = "//";
fjs.parentNode.insertBefore(js, fjs);
}(document, "script", "twitter-wjs");</script>
<script src="" async="async" defer="defer"></script>
<div id="fb-root"></div>
<script>(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); = id;
js.src = "//";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>