You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2015/09/08 06:25:43 UTC

svn commit: r964705 - /websites/production/struts/content/docs/webxml.html

Author: lukaszlenart
Date: Tue Sep  8 04:25:42 2015
New Revision: 964705

Log:
Updates production

Modified:
    websites/production/struts/content/docs/webxml.html

Modified: websites/production/struts/content/docs/webxml.html
==============================================================================
--- websites/production/struts/content/docs/webxml.html (original)
+++ websites/production/struts/content/docs/webxml.html Tue Sep  8 04:25:42 2015
@@ -138,15 +138,37 @@ under the License.
 
     <div class="pagecontent">
         <div class="wiki-content">
-            <div id="ConfluenceContent"><p>The <code>web.xml</code> web application descriptor file represents the core of the Java web application, so it is appropriate that it is also part of the core of the Struts framework. In the <code>web.xml</code> file, Struts defines its FilterDispatcher, the Servlet Filter class that initializes the Struts framework and handles all requests. This filter can contain initialization parameters that affect what, if any, additional configuration files are loaded and how the framework should behave.</p><p>In addition to the FilterDispatcher, Struts also provides an ActionContextCleanUp class that handles special cleanup tasks when other filters, such as those used by Sitemesh, need access to an initialized Struts framework.</p><h2 id="web.xml-SimpleExample">Simple Example</h2><p>Configuring <code>web.xml</code> for the framework is a matter of adding a filter and filter-mapping.</p><div class="code panel pdl" style="border-width: 1px;"><div clas
 s="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>FilterDispatcher Example (web.xml)</b></div><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;web-app id="WebApp_9" version="2.4" 
-	xmlns="http://java.sun.com/xml/ns/j2ee" 
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
-	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;
+            <div id="ConfluenceContent"><p>The <code>web.xml</code> web application descriptor file represents the core of the Java web application, so it is appropriate that it is also part of the core of the Struts framework.  In the <code>web.xml</code> file, Struts defines its FilterDispatcher, the Servlet Filter class that initializes the Struts framework and handles all requests.  This filter can contain initialization parameters that affect what, if any, additional configuration files are loaded and how the framework should behave.</p>
+
+<p>In addition to the FilterDispatcher, Struts also provides an ActionContextCleanUp class that handles special cleanup tasks when other filters, such as those used by Sitemesh, need access to an initialized Struts framework.</p>
+
+<h2 id="web.xml-KeyInitializationParameters">Key Initialization Parameters</h2>
+
+<p></p><p></p>
+<ul></ul><p></p>
+<ul><li><b>config</b> - a comma-delimited list of XML configuration files to load.</li></ul><p></p>
+<ul><li><b>actionPackages</b> - a comma-delimited list of Java packages to scan for Actions.</li></ul><p></p>
+<ul><li><b>configProviders</b> - a comma-delimited list of Java classes that implement the
+ConfigurationProvider interface that should be used for building the Configuration.</li></ul><p></p>
+<ul><li><b>loggerFactory</b> - The class name of the LoggerFactory implementation.</li></ul><p></p>
+<ul><li><b>*</b> - any other parameters are treated as framework constants.</li></ul><p></p>
+
+<p></p>
+
+<h2 id="web.xml-SimpleExample">Simple Example</h2>
+
+<p>Configuring <code>web.xml</code> for the framework is a matter of adding a filter and filter-mapping.</p>
+
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>FilterDispatcher Example (web.xml)</b></div><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+&lt;web-app id=&quot;WebApp_9&quot; version=&quot;2.4&quot; 
+	xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot; 
+	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
+	xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;&gt;
 
     &lt;filter&gt;
         &lt;filter-name&gt;struts2&lt;/filter-name&gt;
-        &lt;filter-class&gt;org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
+        &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
         &lt;init-param&gt;
         	&lt;param-name&gt;actionPackages&lt;/param-name&gt;
         	&lt;param-value&gt;com.mycompany.myapp.actions&lt;/param-value&gt;
@@ -161,23 +183,62 @@ under the License.
     &lt;!-- ... --&gt;
 
 &lt;/web-app&gt;
-</pre>
-</div></div><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Changed Filter Structure in Struts &gt;= 2.1.3</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>To split up the the dispatcher phases, FilterDispatcher is deprecated since Struts 2.1.3. If working with older versions, you need to use</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">    ...
+]]></script>
+</div></div>
+
+    <div class="aui-message warning shadowed information-macro">
+                    <p class="title">Changed Filter Structure in Struts &gt;= 2.1.3</p>
+                            <span class="aui-icon icon-warning">Icon</span>
+                <div class="message-content">
+                            
+<p>To split up the the dispatcher phases, FilterDispatcher is deprecated since Struts 2.1.3. If working with older versions, you need to use</p>
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+    ...
     &lt;filter&gt;
         &lt;filter-name&gt;struts2&lt;/filter-name&gt;
         &lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt;
     ...
-</pre>
-</div></div><p>See <a shape="rect" href="sitemesh-plugin.html">SiteMesh Plugin</a> for an example on when to use seperate Filters for prepare and execution phase</p></div></div><div class="confluence-information-macro confluence-information-macro-note"><p class="title">Why the Filter is mapped with /* and how to configure explicit exclusions (since 2.1.7)</p><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>In the example above we've mapped the Struts 2 dispatcher to <code>/*</code>, so Struts 2 has a crack at all incoming requests. This is because Struts 2 serves static content from its jar files, including Dojo JavaScript files (if using S2.0, or the Dojo plugin in S2.1+) and FreeMarker templates for the Struts 2 tags that produce HTML.</p><p>If we change the filter mapping to something else, for example <code>/*.html</code>, we must take this in to account and extract the content t
 hat would normally be served from the Struts 2 jar files, or some other solution.</p><p>Since Struts 2.1.7, you are able to provide a comma seperated list of patterns for which when matching against the<br clear="none"> request URL the Filter will just pass by. This is done via the configuration option struts.action.excludePattern, for example in your struts.xml</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;struts&gt;
-    &lt;constant name="struts.action.excludePattern" value=".*unfiltered.*,.*\\.nofilter"/&gt;
+]]></script>
+</div></div>
+<p>See <a shape="rect" href="sitemesh-plugin.html">SiteMesh Plugin</a> for an example on when to use seperate Filters for prepare and execution phase</p>
+                    </div>
+    </div>
+
+
+    <div class="aui-message warning shadowed information-macro">
+                    <p class="title">Why the Filter is mapped with /* and how to configure explicit exclusions (since 2.1.7)</p>
+                            <span class="aui-icon icon-warning">Icon</span>
+                <div class="message-content">
+                            
+<p>  In the example above we've mapped the Struts 2 dispatcher to <code>/*</code>, so Struts 2 has a crack at all incoming requests. This is because Struts 2 serves static content from its jar files, including Dojo JavaScript files (if using S2.0, or the Dojo plugin in S2.1+) and FreeMarker templates for the Struts 2 tags that produce HTML.</p>
+
+<p>  If we change the filter mapping to something else, for example <code>/*.html</code>, we must take this in to account and extract the content that would normally be served from the Struts 2 jar files, or some other solution.</p>
+
+<p>  Since Struts 2.1.7, you are able to provide a comma seperated list of patterns for which when matching against the<br clear="none">
+request URL the Filter will just pass by. This is done via the configuration option struts.action.excludePattern, for example in your struts.xml</p>
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+&lt;struts&gt;
+    &lt;constant name=&quot;struts.action.excludePattern&quot; value=&quot;.*unfiltered.*,.*\\.nofilter&quot;/&gt;
     ...
 
 &lt;/struts&gt;
-</pre>
-</div></div></div></div><h2 id="web.xml-TaglibExample">Taglib Example</h2><p>Typically, configuring a taglib is neither required nor recommended. The taglib is included in <code>struts-core.jar</code>, and the container will discover it automatically.</p><p><img class="emoticon emoticon-tick" src="https://cwiki.apache.org/confluence/s/en_GB/5982/f2b47fb3d636c8bc9fd0b11c0ec6d0ae18646be7.1/_/images/icons/emoticons/check.png" data-emoticon-name="tick" alt="(tick)"> If, for some reason, a taglib configuration is needed within web.xml, extract the TLD file from the <code>struts-core.jar</code> <code>META-INF</code> folder, and add a <code>taglib</code> element to the <code>web.xml</code>.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">    &lt;!-- ... --&gt;
+]]></script>
+</div></div>
+                    </div>
+    </div>
+
+
+<h2 id="web.xml-TaglibExample">Taglib Example </h2>
+
+<p>Typically, configuring a taglib is neither required nor recommended. The taglib is included in <code>struts-core.jar</code>, and the container will discover it automatically.</p>
+
+<p><img class="emoticon emoticon-tick" src="https://cwiki.apache.org/confluence/s/en_GB-1988229788/4109/76e0dbb30bc8580e459c201f3535d84f9283a9ac.1/_/images/icons/emoticons/check.png" data-emoticon-name="tick" alt="(tick)">  If, for some reason, a taglib configuration is needed within web.xml, extract the TLD file from the <code>struts-core.jar</code> <code>META-INF</code> folder, and add a <code>taglib</code> element to the <code>web.xml</code>.</p>
+
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+    &lt;!-- ... --&gt;
     &lt;/welcome-file-list&gt;
 
     &lt;taglib&gt;
@@ -185,28 +246,44 @@ under the License.
        &lt;taglib-location&gt;/WEB-INF/struts-tags.tld&lt;/taglib-location&gt;
     &lt;/taglib&gt;
 &lt;/web-app&gt;
-</pre>
-</div></div><h2 id="web.xml-CustomFileManagerandFileManagerFactoryimplementations">Custom FileManager and FileManagerFactory implementations</h2><p>If there is a need to support an App Server's specific file system (eg. VFS in JBoss), you can implement your own version of FileManager. But it must be registered at "the beginning" to support bootstrap of the whole framework.</p><p>To register your own FileManger you can do it with &lt;init-param/&gt; as below:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;filter&gt;
+]]></script>
+</div></div>
+
+<h2 id="web.xml-CustomFileManagerandFileManagerFactoryimplementations">Custom FileManager and FileManagerFactory implementations</h2>
+
+<p>If there is a need to support an App Server's specific file system (eg. VFS in JBoss), you can implement your own version of FileManager. But it must be registered at "the beginning" to support bootstrap of the whole framework.</p>
+
+<p>To register your own FileManger you can do it with &lt;init-param/&gt; as below:</p>
+
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+&lt;filter&gt;
      &lt;filter-name&gt;struts2&lt;/filter-name&gt;
-     &lt;filter-class&gt;org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
+     &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;struts.fileManager&lt;/param-name&gt;
          &lt;param-value&gt;com.company.MyFileManager&lt;/param-value&gt;
      &lt;/init-param&gt;
 &lt;/filter&gt;
-</pre>
-</div></div><p>You can as well register your own FileManagerFactory with &lt;init-param/&gt;, see example:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<pre class="brush: xml; gutter: false; theme: Default" style="font-size:12px;">&lt;filter&gt;
+]]></script>
+</div></div>
+
+<p>You can as well register your own FileManagerFactory with &lt;init-param/&gt;, see example:</p>
+
+<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<script class="theme: Default; brush: xml; gutter: false" type="syntaxhighlighter"><![CDATA[
+&lt;filter&gt;
      &lt;filter-name&gt;struts2&lt;/filter-name&gt;
-     &lt;filter-class&gt;org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
+     &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;struts.fileManagerFactory&lt;/param-name&gt;
          &lt;param-value&gt;com.company.MyFileManagerFactory&lt;/param-value&gt;
      &lt;/init-param&gt;
 &lt;/filter&gt;
-</pre>
-</div></div><p>Take a look on default implementations - DefaultFileManager.java and DefaultFileManagerFactory.java to understand how and why.</p></div>
+]]></script>
+</div></div>
+
+<p>Take a look on default implementations - DefaultFileManager.java and DefaultFileManagerFactory.java to understand how and why.</p></div>
         </div>