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

📄 newbie.fml

📁 ActionServlet源码 struts的一个步骤都有 知道本来有视频的太大了 就没有上传了
💻 FML
📖 第 1 页 / 共 4 页
字号:
<?xml version="1.0"?>
<!--
    $Id: newbie.fml 481833 2006-12-03 17:32:52Z niallp $

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at
   
         http://www.apache.org/licenses/LICENSE-2.0
   
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<!--
// ======================================================================== 78
-->
<faqs title="Newbie FAQ">
        <part id="general">

            <faq id="chain">
                <question>How do I load a custom chain config file?</question>
                <answer>

                    <p>Use the <code>chainConfig</code> init param for
                        ActionServlet to specify a comma delimited list of 
                        chain config files.
                    </p>

                    <p>This will override the default value of
                        <code>chainConfig</code>, so unless you are
                        overriding the default request processing chain, you
                        must include the default chain config file in the list.
                    </p>

                    <pre>
                        &lt;init-param>
                            &lt;param-name>chainConfig&lt;/param-name>
                            &lt;param-value>
                                org/apache/struts/chain/chain-config.xml,
                                /WEB-INF/custom-chain-config.xml
                            &lt;/param-value>
                        &lt;/init-param>
                    </pre>

                    <p>For another method of loading chain config files, see
                        <a href="http://jakarta.apache.org/commons/chain/cookbook.html#Load_a_Catalog_From_a_Web_Application">
                            Load a Catalog From a Web Application</a>
                        in the Commons Chain Cookbook.
                    </p>
                </answer>

            </faq>

            <faq id="modules">
	    <question>What is a modular application? What does module-relative mean?</question>                    
            <answer>
                <p>
                    Since Struts 1.1, the framework supports multiple
                    application modules. All applications have at
                    least one root, or default, module. Like the root
                    directory in a file system, the default application
                    has no name. (Or is named with an empty string, depending
                    your viewpoint.) Developing an application
                    with only a default module is no different from how
                    applications were developed under Struts 1.0.
                    Since Struts 1.1, you can add additional modules to your
                    application, each of which can have their
                    own configuration files, messages resources, and so forth.
                    Each module is developed in the same way as
                    the default module. Applications that were developed as a
                    single module can added to a multiple
                    module application, and modules can promoted to a
                    standalone application without change. For more
                    about configuring your application to support multiple
                    modules, see
                    <a href="../userGuide/configuration.html#dd_config_modules">
                        Configuring Applications</a>
                    in the
                    User Guide.
                </p>

                <p>
                    But to answer the question =:0), a modular application is
                    an application that uses more than
                    one module. Module-relative means that the URI starts at
                    the module level, rather than at
                    the context level, or the absolute-URL level.
                </p>
                <ul>
                    <li>Absolute URL:
                        http://localhost/myApplication/myModule/myAction.do</li>
                    <li>context-relative: /myModule/myAction.do</li>
                    <li>module-relative: /myAction.do</li>
                </ul>

                <p>
                    The Struts Examples application is a modular application
                    that was assembled from several
                    applications that were created independently.
                </p>
            </answer>
            </faq>

            <faq id="naming">
            <question>Why are some of the class and element names counter-intuitive?</question>
            <answer>
                <p>
                    The framework grew in the telling and, as it evolved, some
                    of the names
                    drifted.
                </p>
                <p>The good thing about a nightly build, is that everything
                    becomes
                    available to the community as soon as it is written. The
                    bad thing about
                    a nightly build is that things like class names get locked
                    down early and
                    then become difficult to change.
                </p>
            </answer>
            </faq>

            <faq id="actionForms">
            <question>Whither ActionForms?</question>
	    <answer>
                <p>
                    <a href="http://www.mail-archive.com/struts-user@jakarta.apache.org/msg19281.html">
                        http://www.mail-archive.com/struts-user@jakarta.apache.org/msg19281.html</a>
                    <br/>
                    <a href="http://www.mail-archive.com/struts-user@jakarta.apache.org/msg19338.html">
                        http://www.mail-archive.com/struts-user@jakarta.apache.org/msg19338.html</a>
                    <br/>
                    <a href="http://www.mail-archive.com/struts-user@jakarta.apache.org/msg20833.html">
                        http://www.mail-archive.com/struts-user@jakarta.apache.org/msg20833.html</a>
                    <br/>
                </p>
            </answer>
            </faq>

            <faq id="actionFormInterface">
            <question>Why is ActionForm a base class rather than an interface?</question>
            <answer>
                <p>
                    Originally, the rationale as that making ActionForm a
                    class takes advantage of the single
                    inheritance restriction of Java to it makes it more
                    difficult for people to do
                    things that they should not do. At the time, EJBs were
                    becoming popular, and
                    most developers were trying to combine EJB remoting with
                    ActionForms,
                    and the result was not pretty.
                </p>
                <p>
                    Since then, most developers use different approaches to
                    data persistent,
                    and most developers now have a good understanding of why
                    we want to separate
                    the model from the view.
                    Accordingly, we do plan to introduce more interfaces into
                    the framework.
                    It's just a matter of when.
                </p>
                <p>
                    Meanwhile, DynaActionForms relieve developers of
                    maintaining simple ActionForms.
                    For near zero maintenance, try
                    <a href="../userGuide/building_controller.html#lazy_action_form_classes/">
                        LazyActionForm</a>
                    and Hubert Rabago's
                    <a href="https://formdef.dev.java.net/">FormDef.</a>
                </p>
            </answer>
            </faq>

            <faq id="JavaBeans">
            <question>Do ActionForms have to be true JavaBeans?</question>
            <answer>
                <p>
                    The utilities that the framework uses (Commons-BeanUtils
                    since 1.1) require that ActionForm properties follow
                    the JavaBean patterns for mutators and accessors
                    (get*,set*,is*). Since the framework uses the
                    Introspection API
                    with the ActionForms, some containers may require that all
                    the JavaBean patterns be followed, including
                    declaring 
                    <code>"implements Serializable"</code>
                    for each subclass. The safest thing is to review the
                    <a href="../userGuide/preface.html#javabeans">JavaBean
                        specification</a>
                    and follow all the prescribed patterns.
                </p>
                <p>
                    Since Struts 1.1, you can also use DynaActionForms and
                    mapped-backed forms, which are not true JavaBeans.
                    For more see
                    <a href="../userGuide/building_controller.html#action_form_classes">
                        ActionForm classes</a>
                    in the User Guide
                    and
                    <a href="#otherBeans">Using Hashmaps with ActionForms</a>
                    in this FAQ.
                </p>
            </answer>
            </faq>

            <faq id="otherBeans">
            <question>Can I use other beans or hashmaps with ActionForms?</question>
            <answer>
                <p>
                    Yes. There are several ways that you can use other beans
                    or hashmaps with ActionForms.
                </p>
                <ul>
                    <li>
                        ActionForms can have other beans or hashmaps as
                        properties
                    </li>
                    <li>
                        "Value Beans" or "Data Transfer Objects" (DTOs) can be
                        used independently of
                        ActionForms to transfer data to the view
                    </li>
                    <li>
                        ActionForms can use Maps to support "dynamic"
                        properties (since Struts 1.1)
                    </li>
                </ul>
                <p>
                    ActionForms (a.k.a. "form beans") are really just JavaBeans
                    (with a few special methods) that the framework creates
                    and puts into session or request scope for you.
                    There is nothing preventing you from using other beans, or
                    including them in your form beans. 
                    Let's look at some examples.
                </p>
                <p>
                    <em>Collections as properties</em>
                    Suppose that you need to display a pulldown list of
                    available colors on an input form in your application. You
                    can include a string-valued
                    <code>colorSelected</code>
                    property in your
                    <code>ActionForm</code>
                    to represent the user's
                    selection and a
                    <code>colorOptions</code>
                    property implemented as a
                    <code>Collection</code>
                    (of strings) to store the available color choices.
                    Assuming that you have defined the getters
                    and setters for the
                    <code>colorSelected</code>
                    and
                    <code>colorOptions</code>
                    properties
                    in your
                    <code>orderEntryForm</code>
                    form bean, you can render the
                    pulldown list using:
                </p>
                <source>
                    &lt;html:select property="colorSelected"&gt;
                    &lt;html:options property="colorOptions"
                    name="orderEntryForm"/&gt;
                    &lt;/html:select&gt;
                </source>
                <p>
                    The list will be populated using the strings in the
                    <code>colorOptions</code>
                    collection of the
                    <code>orderEntryForm</code>
                    and the value that the user selects
                    will go into the
                    <code>colorSelected</code>
                    property that gets posted to the subsequent
                    <code>Action</code>
                    . Note that we are assuming here that the
                    <code>colorOptions</code>
                    property of the
                    <code>orderEntryForm</code>
                    has already been set.
                </p>
                <p>
                    See
                    <a href="#prepopulate">How can I prepopulate a form?</a>
                    for instructions on how to set
                    form bean properties before rendering edit forms that
                    expect properties to be pre-set.
                </p>
                <p>
                    <em>Independent DTO</em>
                    An
                    <code>Action</code>
                    that retrieves a list of open orders (as an
                    <code>ArrayList</code>
                    of
                    <code>Order</code>
                    objects) can use a DTO independently of any
                    form bean to transfer search results to the view. First,
                    the Action's
                    <code>execute</code>
                    method performs the search and puts the DTO into the
                    request:
                </p>
                <source>
                    ArrayList results =
                    businessObject.executeSearch(searchParameters);
                    request.setAttribute("searchResults",results);
                </source>
                <p>
                    Then the view can iterate through the results using the
                    "searchResults" request key to
                    reference the DTO:
                    `</p>
                <source>
                    &lt;logic:iterate id="order" name="searchResults"
                    type="com.foo.bar.Order"&gt;
                    &lt;tr&gt;&lt;td&gt;&lt;bean:write name="order"
                    property="orderNumber"/&gt;&lt;td&gt;
                    &lt;td&gt;..other properties...&lt;/td&gt;&lt;/tr&gt;
                    &lt;/logic:iterate&gt;
                </source>

⌨️ 快捷键说明

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