⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 configuration.html

📁 struts api,学习使用struts必备的文档
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>The Struts User's Guide - Configuring Applications</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="Craig R. McClanahan" name="author" />
<meta content="Mike Schachter" name="author" />
<meta content="Ted Husted" name="author" />
<meta content="Martin Cooper" name="author" />
<meta content="Ed Burns" name="author" />
<meta content="Donald Ball" name="author" />
<meta content="Eddie Bush" name="author" />
<meta content="Yann Cebron" name="author" />
<meta content="David Graham" name="author" />
<meta content="Tim O'Brien" name="author" />
<link href="../struts.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="heading">
<a href="http://apache.org/">
<img id="asf_logo_wide" alt="The Apache Project" src="../images/asf_logo_wide.gif" />
</a>
<a href="http://struts.apache.org/">
<img id="struts-logo" alt="Struts Framework" src="../images/struts.gif" />
</a>
</div>
<!--end heading-->
<div id="content">
<div id="menu">

    
    
    <p>User Guide</p>
<ul>
      <li>
<a href="index.html">Table of Contents</a>
</li>
      <li>
<a href="preface.html">Preface</a>
</li>
      <li>
<a href="introduction.html">Introduction</a>
</li>
      <li>
<a href="building_model.html">Model Components</a>
</li>
      <li>
<a href="building_view.html">View Components</a>
</li>
      <li>
<a href="building_controller.html">Controller Components</a>
</li>
      <li>
<a href="configuration.html">Configuration</a>
</li>
      <li>
<a href="release-notes.html">Release Notes</a>
</li>
      <li>
<a href="installation.html">Installation</a>
</li>
    </ul>

    <p>Developer Guides</p>
<ul>
        <li>
<a href="dev_bean.html">Bean Tags</a>
</li>
        <li>
<a href="dev_html.html">HTML Tags</a>
</li>
        <li>
<a href="dev_logic.html">Logic Tags</a>
</li>
        <li>
<a href="dev_nested.html">Nested Tags</a>
</li>
        <li>
<a href="dev_tiles.html">Tiles Tags</a>
</li>
        <li>
<a href="dev_util.html">Utilities</a>
</li>
        <li>
<a href="dev_validator.html">Validator</a>
</li>
    </ul>

    <p>Quick Links</p>
<ul>
        <li>
<a href="../index.html">Welcome</a>
</li>
        <li>
<a href="index.html">User and Developer Guides *</a>
</li>
        <li>
<a href="../faqs/index.html">FAQs and HowTos</a>
</li>
    </ul>

<div class="authors">
<p>
<strong>Contributors</strong>
</p>
<ul>
<li>Craig R. McClanahan</li>
<li>Mike Schachter</li>
<li>Ted Husted</li>
<li>Martin Cooper</li>
<li>Ed Burns</li>
<li>Donald Ball</li>
<li>Eddie Bush</li>
<li>Yann Cebron</li>
<li>David Graham</li>
<li>Tim O'Brien</li>
</ul>
</div>
</div>
<!--end menu-->
<div id="main">
<h1 id="config_apps">5. Configuring Applications</h1>
<h2 id="config-overview">5.1 Overview</h2>
<div class="indent">

    <p>
    Before you can build an application, you need to lay a solid foundation.
    There are several setup tasks you need to perform before deploying
    your Struts application.
    These include components in the Struts configuration file
    and in the Web Application Deployment Descriptor.
    </p>

 </div>
<h2 id="struts-config">5.2 The Struts configuration file</h2>
<div class="indent">

    <p>
    The <a href="building_controller.html#config">Building Controller
    Components</a> chapter covered writing the <code>&lt;form-bean&gt;</code> and
    <code>&lt;action-mapping&gt;</code> portions of the Struts configuration file.
    These elements usually play an important role in the development of a
    Struts application.
    The other elements in Struts configuration file tend to be static:
    you set them once and leave them alone.
    </p>

    <p>
    These "static" configuration elements are:
    </p>

    <ul>

        <li>
            &lt;controller&gt;
        </li>

        <li>
            &lt;message-resources&gt;
        </li>

        <li>
            &lt;plug-in&gt;
        </li>

        <li>
            &lt;data-sources&gt;
        </li>

    </ul>

 </div>
<h2 id="controller_config">5.2.1 Controller Configuration</h2>
<div class="indent">

    <p>
    The <code>&lt;controller&gt;</code> element allows you to configure
    the ActionServlet.
    Many of the controller parameters were previously defined by servlet
    initialization parameters in your <code>web.xml</code> file but have been
    moved to this section of <code>struts-config.xml</code> in order to allow
    different modules in the same web application to be configured differently.
    For full details on available parameters see the
    <a href="http://struts.apache.org/dtds/struts-config_1_2.dtd">
    struts-config_1_2.dtd</a> or the list below.
    </p>



    <ul>

        <li>
        <strong>bufferSize</strong> - The size (in bytes) of the input buffer
        used when processing file uploads.
        [4096] (optional)
        </li>

        <li>
        <strong>className</strong> - Classname of configuration bean.
        [org.apache.struts.config.ControllerConfig] (optional)
        </li>

        <li>
        <strong>contentType</strong> - Default content type (and optional character
        encoding) to be set on each response.
        May be overridden by the Action, JSP, or other resource to which
        the request is forwarded.
        [text/html] (optional)
        </li>

        <li>
        <strong>forwardPattern</strong> - Replacement pattern defining how the "path"
        attribute of a <code>&lt;forward&gt;</code> element is mapped to a
        context-relative URL when it starts with a slash (and when the
        <code>contextRelative</code> property is <code>false</code>).
        This value may consist of any combination of the following:

        <ul>

            <li>
            <em>$M</em> - Replaced by the module prefix of this module.
            </li>

            <li>
            <em>$P</em> - Replaced by the "path" attribute of the selected
            <code>&lt;forward&gt;</code> element.
            </li>

            <li>
            <em>$$</em> - Causes a literal dollar sign to be rendered.
            </li>

            <li>
            <em>$x</em> - (Where "x" is any character not defined above)
            Silently swallowed, reserved for future use.
            </li>

        </ul>

        If not specified, the default forwardPattern is consistent with the
        previous behavior of forwards.
        [$M$P] (optional)
        </li>

        <li>
        <strong>inputForward</strong> - Set to <code>true</code> if you want the
        <code>input</code> attribute of <code>&lt;action&gt;</code> elements
        to be the name of a local or global <code>ActionForward</code>, which
        will then be used to calculate the ultimate URL.
        Set to <code>false</code> to treat the <code>input</code> parameter of
        <code>&lt;action&gt;</code> elements as a module-relative path to
        the resource to be used as the input form.
        [false] (optional)
        </li>

        <li>
        <strong>locale</strong> - Set to <code>true</code> if you want a
        <code>Locale</code> object stored in the user's session if not already
        present.
        [true] (optional)
        </li>

        <li>
        <strong>maxFileSize</strong> - The maximum size (in bytes) of a file to be
        accepted as a file upload.
        Can be expressed as a number followed by a "K", "M", or "G",
        which are interpreted to mean kilobytes, megabytes, or gigabytes,
        respectively.
        [250M] (optional)
        </li>

        <li>
        <strong>multipartClass</strong> - The fully qualified Java class name of the
        multipart request handler class to be used with this module.
        [org.apache.struts.upload.CommonsMultipartRequestHandler] (optional)
        </li>

        <li>
        <strong>nocache</strong> - Set to <code>true</code> if you want the controller
        to add HTTP headers for defeating caching to every response from
        this module.
        [false] (optional)
        </li>

        <li>
        <strong>pagePattern</strong> - Replacement pattern defining how the
        <code>page</code> attribute of custom tags using it is mapped to a
        context-relative URL of the corresponding resource.
        This value may consist of any combination of the following:

        <ul>

            <li>
            <em>$M</em> - Replaced by the module prefix of this module.
            </li>

            <li>
            <em>$P</em> - Replaced by the "path" attribute of the selected
            <code>&lt;forward&gt;</code> element.

            </li>
            <li>
            <em>$$</em> - Causes a literal dollar sign to be rendered.
            </li>

            <li>
            <em>$x</em> - (Where "x" is any character not defined above)
              Silently swallowed, reserved for future use.
            </li>

        </ul>

        If not specified, the default pagePattern is consistent with the
        previous behavior of URL calculation.
        [$M$P] (optional)
        </li>
        <li>

        <strong>processorClass</strong> - The fully qualified Java class name of the
        <code>RequestProcessor</code> subclass to be used with this module.
        [org.apache.struts.action.RequestProcessor] (optional)
        </li>

        <li>
        <strong>tempDir</strong> - Temporary working directory to use when processing
        file uploads.
        [{the directory provided by the servlet container}]
        </li>

    </ul>



    <p>
    This example uses the default values for several controller parameters.
    If you only want default behavior you can omit the controller section
    altogether.
    </p>

<pre>
<code>
&lt;controller
    processorClass="org.apache.struts.action.RequestProcessor"
       contentType="text/html"/&gt;;
</code>
</pre>

</div>
<h2 id="resources_config">5.2.2 Message Resources Configuration</h2>
<div class="indent">

    <p>
    Struts has built in support for internationalization (I18N).
    You can define one or more <code>&lt;message-resources&gt;</code> elements
    for your webapp; modules can define their own resource bundles.
    Different bundles can be used simultaneously in your application, the 'key'
    attribute is used to specify the desired bundle.
    </p>



    <ul>

        <li>
        <strong>className</strong> - Classname of configuration bean.
        [org.apache.struts.config.MessageResourcesConfig] (optional)
        </li>

        <li>
        <strong>factory</strong> - Classname of MessageResourcesFactory.
        [org.apache.struts.util.PropertyMessageResourcesFactory] (optional)
        </li>

        <li>
        <strong>key</strong> - ServletContext attribute key to store this bundle.
        [org.apache.struts.action.MESSAGE] (optional)
        </li>

        <li>
        <strong>null</strong> - Set to <code>false</code> to display missing resource
        keys in your application like '<em>???keyname???</em>' instead of
        <code>null</code>.
        [true] (optional)
        </li>

        <li>
        <strong>parameter</strong> - Name of the resource bundle. (required)
        </li>

    </ul>



    <p>Example configuration:</p>

<pre>
<code>
&lt;message-resources
    parameter="MyWebAppResources"
         null="false" /&gt;
</code>
</pre>

    <p>
    This would set up a message resource bundle provided in the file
    <code>MyWebAppResources.properties</code> under the default key.
    Missing resource keys would be displayed as '<em>???keyname???</em>'.
    </p>

</div>
<h2 id="plugin_config">5.2.3 PlugIn Configuration</h2>
<div class="indent">

    <p>
    Struts PlugIns are configured using the <code>&lt;plug-in&gt;</code>
    element within the Struts configuration file.
    This element has only one valid attribute, 'className', which is the fully
    qualified name of the Java class which implements the
    <code>org.apache.struts.action.PlugIn</code> interface.
    </p>

    <p>
    For PlugIns that require configuration themselves, the nested
    <code>&lt;set-property&gt;</code> element is available.
    </p>

    <p>
    This is an example using the Tiles plugin:
    </p>

<pre>
<code>
&lt;plug-in className="org.apache.struts.tiles.TilesPlugin"&gt;
    &lt;set-property
        property="definitions-config"
           value="/WEB-INF/tiles-defs.xml"/&gt;
&lt;/plug-in&gt;
</code>
</pre>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -