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

📄 building_view.html

📁 struts api,学习使用struts必备的文档
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<strong>linkSubscription</strong> - Generates a hyperlink to a details page
    for a Subscription, which passes the required primary key values as
    request attributes.  This is used when listing the subscriptions associated
    with a user, and providing links to edit or delete them.</li>
    <li>
<strong>linkUser</strong> - Generates a hyperlink to a details page
    for a User, which passes the required primary key values as
    request attributes.</li>
    </ul>

    <p>
    The source code for these tags is in the <code>src/example</code> directory,
    in package <code>org.apache.struts.example</code>, along with the other Java
    classes that are used in this application.
    </p>
</div>
<h2 id="includes">3.4.2 Page Composition With Includes</h2>
<div class="indent">

    <p>
    Creating the entire presentation of a page in one JSP file (with custom
    tags and beans to access the required dynamic data) is a very common 
    design approach, and was employed in the example application included 
    with Struts.
    However, many applications require the display of multiple logically 
    distinct portions of your application together on a single page.
    </p>

    <p>
    For example, a portal application might have some or all of the following
    functional capabilities available on the portal's "home" page:
    </p>

    <ul>
    
        <li>
        Access to a search engine for this portal.
        </li>

        <li>
        One or more "news feed" displays, with the topics of interest 
        customizedfrom the user's registration profile.
        </li>

        <li>
        Access to discussion topics related to this portal.
        </li>

        <li>
        A "mail waiting" indicator if your portal provides free email
        accounts.
        </li>
    
    </ul>

    <p>
    The development of the various segments of this site is easier if you
    can divide up the work, and assign different developers to the different
    segments.  
    Then, you can use the <em>include</em> capability of JavaServer Pages
    technology to combine the results into a single result page, or use the 
    include tag provided with Struts.  
    There are three types of <em>include</em> available, depending on when you w
    ant the combination of output to occur:
    </p>

    <ul>
    
        <li>
        An <code>&lt;%@ include file="xxxxx" %&gt;</code> directive can 
        include a file that contains Java code or JSP tags. 
        The code in the included file can even reference variables declared 
        earlier in the outer jsp page. 
        The code is inlined into the other JavaServer Page before it is 
        compiled so it can definitely contain more than just HTML.
        </li>

        <li>
        The include <em>action</em> (<code>&lt;jsp:include page="xxxxx"
        flush="true" /&gt;</code>) is processed at request time, and is 
        handled transparently by the server.  
        Among other things, that means you can conditionally perform the 
        include by nesting it within a tag like 
        <a href="struts-logic.html#equal">equal</a> by using it's
        parameter attribute.
        </li>

        <li>
        The <a href="struts-bean.html#include">bean:include</a> 
        tag takes either a an argument "forward" representing a logical name 
        mapped to the jsp to include, or the "id" argument, which represents a 
        page context String variable to print out to the jsp page.
        </li>
    
    </ul>

</div>
<h2 id="Tiles">3.4.3 Page Composition With Tiles</h2>
<div class="indent">

    <p>
    Tiles is a powerful templating library that allows you to construct views 
    by combining various "tiles".  
    Here's a quick setup guide:
    </p>

    <ol>
        <li>
        Create a /layout/layout.jsp file that contains your app's common look and 
        feel:
    
<pre>
<code>
&lt;html&gt;
&lt;body&gt;
&lt;tiles:insert attribute="body"/&gt;
&lt;/body&gt;
&lt;/html&gt;
</code>
</pre>
        </li>
        
        <li>
    Create your /index.jsp homepage file:
    
<pre>
<code>
&lt;h1&gt;This is my homepage&lt;/h1&gt;
</code>
</pre>

        </li>

        <li>
        Create a /WEB-INF/tiles-defs.xml file that looks like this:

<pre>
<code>
&lt;tiles-definitions&gt;
&lt;definition 
    name="layout" 
    path="/layout/layout.jsp"&gt;
    &lt;put name="body" value=""/&gt;
&lt;/definition&gt;
&lt;definition name="homepage" extends="layout"&gt;
    &lt;put 
        name="body" 
        value="/index.jsp"/&gt;
&lt;/definition&gt;
&lt;tiles-definitions&gt;
</code>
</pre>
        </li>

        <li>
        Setup the TilesPlugin in the struts-config.xml file:
        
<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>
        </li>
        
        <li>
        Setup an action mapping in struts-config.xml to point to your 
        homepage tile:

<pre>
<code>
&lt;action 
path="/index"
type="org.apache.struts.actions.ForwardAction"
parameter="homepage"/&gt;
</code>
</pre>
        </li>
        </ol>

        <p>
        The TilesPlugin configures a special RequestProcessor that determines 
        if the requested view is a tile and processes it accordingly.  
        Note that we made the homepage tile extend our root layout tile and 
        changed the body attribute.  
        Tiles inserts the file named in the body attribute into the main 
        layout.
        </p>

        <p>
        See the tiles-documentation webapp for in-depth examples.
        </p>
  
  </div>
<h2 id="image_rendering">3.4.4 Image Rendering Components</h2>
<div class="indent">

        <p>
        Some applications require dynamically generated images, like the 
        price charts on a stock reporting site.  
        Two different approaches are commonly  used to meet these 
        requirements:
        </p>

    <ul>
  
        <li>
        Render a hyperlink with a URL that executes a servlet request.  
        The servlet will use a graphics library to render the graphical image,
        set the content type appropriately (such as to 
        <code>image/gif</code>), and send back the bytes of that image to the 
        browser, which will display them just as if it had received a static 
        file.
        </li>

        <li>
        Render the HTML code necessary to download a Java applet that 
        creates the required graph.  
        You can configure the graph by setting appropriate initialization 
        parameters for the applet in the rendered code, or you can have the 
        applet make its own connection to the server to receive
        these parameters.
        </li>
        
    </ul>
    
  </div>
<h2 id="text_rendering">3.4.5 Rendering Text</h2>
<div class="indent">

    <p>
    Some applications require dynamically generated text or markup,
    such as XML. 
    If a complete page is being rendered, and can be output using a 
    PrintWriter, this is very easy to do from an Action:
    </p>

<pre>
<code>
response.setContentType("text/plain"); // or text/xml
PrintWriter writer = response.getWriter();
// use writer to render text
return(null);
</code>
</pre>

</div>
<h2 id="struts-el">3.4.6 The Struts-EL Tag Library</h2>
<div class="indent">
    
    <p>
    The <strong>Struts-EL</strong> tag library is a contributed library in
    the Struts distribution.  
    It represents an integration of the Struts tag library with the JavaServer 
    Pages Standard Tag Library, or at least the "expression evaluation" 
    engine that is used by the JSTL.
    </p>

    <p>
    The base Struts tag library contains tags which rely on the evaluation
    of "rtexprvalue"s (runtime scriptlet expressions) to evaluate dynamic
    attribute values.  For instance, to print a message from a properties
    file based on a resource key, you would use the
    <code>bean:write</code> tag, perhaps like this:</p>
    <pre>
<code>
    &lt;bean:message key='&lt;%= stringvar %&gt;'/&gt;
    </code>
</pre>

    <p>
    This assumes that <code>stringvar</code> exists as a JSP scripting
    variable.  If you're using the <strong>Struts-EL</strong> library, the
    reference looks very similar, but slightly different, like this:</p>
    <pre>
<code>
    &lt;bean-el:message key="${stringvar}"/&gt;
    </code>
</pre>

    <p>
    If you want to know how to properly use the <strong>Struts-EL</strong>
    tag library, there are two important things you need to know:
    </p>
    
    <ul>
    
        <li>
        The Struts tag library
        </li>

        <li>
        The JavaServer Pages Standard tag library
        </li>

    </ul>


    <p>
    Once you understand how to use these two, consider Struts tag
    attribute values being evaluated the same way the JSTL tag attribute
    values are.  
    Past that, there is very little else you need to know to effectively use 
    the <strong>Struts-EL</strong> tag library.
    </p>
    
    <p>
    Although the <strong>Struts-EL</strong> tag library is a direct "port"
    of the tags from the Struts tag library, not all of the tags in the
    Struts tag library were implemented in the <strong>Struts-EL</strong>
    tag library.  
    This was the case if it was clear that the functionality of a particular 
    Struts tag could be entirely fulfilled by a tag in the JSTL.  
    It is assumed that developers will want to use the 
    <strong>Struts-EL</strong> tag library along with the JSTL, so it is 
    reasonable to assume that they will use tags from the JSTL if they
    fill their needs.
    </p>

    <p>
    For more see, <a href="../faqs/struts-el.html">Struts-El Extension</a> in the FAQ/HOWTO section.
    </p>

</div>
<hr class="section" />
<div class="indent">
    <p class="right">
    Next: <a href="building_controller.html">Building Controller 
    Components</a>
    </p>
</div>
</div>
<!--end main-->
</div>
<!--end content-->
<div id="footer">
<img id="powered-logo" alt="Powered by Struts" src="../images/struts-power.gif" />
        Copyright (c) 2000-2005, The Apache Software Foundation <span class="noprint">- 
        <a href="http://wiki.apache.org/struts/StrutsDocComments">Comments?</a>
</span>
</div>
<!--end footer-->
</body>
</html>

⌨️ 快捷键说明

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