用struts wml標記來實現wap開發--tiles篇

先定義tiles:
<?xml version="1.0" encoding="ISO-8859-1" ?>

 <!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration//EN"
       "http://jakarta.apache.org/struts/dtds/tiles-config.dtd">


<!--
     This is a blank Tiles definition file with a commented example.
-->

<tiles-definitions>

   
    <definition name=".mainLayout" path="/WEB-INF/pages/common/layout/layout.jsp">
        <put name="title"  value="wap site Title" />
        <put name="header" value="this is header" />
  <put name="left" value="this is header" />
  <put name="body"   value="this is body" />
  <put name="right" value="this is right" />
        <put name="menu"   value="this is menu" />
        <put name="footer" value="this is foot" />
    </definition>
 <!-- sample tiles definitions
    <definition name=".mainMenu" path="/common/layouts/vboxLayout.jsp" >
        <putList name="list" >
            <add value=".menu.links" />
            <add value=".menu.taglib.references" />
            <add value=".menu.printer.friendly" />
            <add value=".menu.old.documents" />
      </putList>
    </definition>
 
    <definition name="aPage" extends=".mainLayout">
        <put name="title"  value="Another Title" />
        <put name="body"   value=".aPage.body" />
    </definition>
 
    end samples -->

</tiles-definitions>

layout.jsp:

<%@ page contentType="text/vnd.wap.wml; charset=UTF-8" %>
<%@ include file="/WEB-INF/pages/common/taglibs.jsp"%>
<wml:wml>
 <card>
  <center>
   <tiles:getAsString name="title" />
   <table columns="1">
    <tr>
     <td align="center">
      <p align="center"><tiles:getAsString name="header" /></p>
     </td>
    </tr>
   </table>
   <table columns="1">
    <tr>
     <td align="center">
      <p align="center"><tiles:getAsString name="menu" /></p>
     </td>
    </tr>
   </table>
   <table columns="3">
    <tr>
     <td width="10%">
      <tiles:getAsString name="left" />
     </td>
     <td width="80%">
      <tiles:getAsString name="body" />
     </td>
     <td width="10%">
      <tiles:getAsString name="right" />
     </td>
    </tr>
   </table>
   <table columns="1">
    <tr>
     <td>
      <tiles:getAsString name="footer" />
     </td>
    </tr>
   </table>
  </center>
 </card>
</wml:wml>

taglibs.jsp:
<%@ taglib uri="/WEB-INF/app.tld"    prefix="app" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-wml.tld" prefix="wml" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld"      prefix="tiles" %>

struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<!--
     This is the Struts configuration file for the example application,
     using the proposed new syntax.

     NOTE:  You would only flesh out the details in the "form-bean"
     declarations if you had a generator tool that used them to create
     the corresponding Java classes for you.  Otherwise, you would
     need only the "form-bean" element itself, with the corresponding
     "name" and "type" attributes.
-->


<struts-config>


  <!-- ========== Data Source Configuration =============================== -->
<!--
 <data-sources>
   <data-source>
     <set-property property="autoCommit"
                      value="false"/>
     <set-property property="description"
                      value="Example Data Source Configuration"/>
     <set-property property="driverClass"
                      value="org.postgresql.Driver"/>
     <set-property property="maxCount"
                      value="4"/>
     <set-property property="minCount"
                      value="2"/>
     <set-property property="password"
                      value="mypassword"/>
     <set-property property="url"
                      value="jdbc:postgresql://localhost/mydatabase"/>
     <set-property property="user"
                      value="myusername"/>
   </data-source>
 </data-sources>
-->
  <!-- ========== Form Bean Definitions =================================== -->
  <form-beans>

    <!-- Logon form bean -->
<!--
    <form-bean      name="logonForm"
                    type="org.apache.struts.webapp.example.LogonForm"/>
-->
<!--
    <form-bean      name="logonForm"
                    type="org.apache.struts.action.DynaActionForm">
-->
    <form-bean      name="logonForm"
                    type="org.apache.struts.validator.DynaValidatorForm">
      <form-property name="username" type="java.lang.String"/>
      <form-property name="password" type="java.lang.String"/>
    </form-bean>


    <!-- Registration form bean -->
    <form-bean      name="registrationForm"
                    type="org.apache.struts.webapp.example.RegistrationForm"/>

    <!-- Subscription form bean -->
    <form-bean      name="subscriptionForm"
                    type="org.apache.struts.webapp.example.SubscriptionForm"/>

  </form-beans>


  <!-- ========== Global Forward Definitions ============================== -->
  <global-forwards>
    <forward   name="logoff"               path="/logoff.do"/>
    <forward   name="logon"                path="/logon.jsp"/>
    <forward   name="registration"         path="/registration.jsp"/>
    <forward   name="success"              path="/mainMenu.jsp"/>
  </global-forwards>


  <!-- ========== Action Mapping Definitions ============================== -->
  <action-mappings>

    <!-- Edit user registration -->
    <action    path="/editRegistration"
               type="org.apache.struts.webapp.example.EditRegistrationAction"
          attribute="registrationForm"
              scope="request"
           validate="false">
      <forward name="success"              path="/registration.jsp"/>
    </action>

    <!-- Edit mail subscription -->
    <action    path="/editSubscription"
               type="org.apache.struts.webapp.example.EditSubscriptionAction"
          attribute="subscriptionForm"
              scope="request"
           validate="false">
      <forward name="failure"              path="/mainMenu.jsp"/>
      <forward name="success"              path="/subscription.jsp"/>
    </action>

    <!-- Process a user logoff -->
    <action    path="/logoff"
               type="org.apache.struts.webapp.example.LogoffAction">
      <forward name="success"              path=".mainLayout"/><!--/index.jsp-->
    </action>

    <!-- Process a user logon -->
    <action    path="/logon"
               type="org.apache.struts.webapp.example.LogonAction"
               name="logonForm"
              scope="session"
              input="logon">
      <exception
                key="expired.password"
               type="org.apache.struts.webapp.example.ExpiredPasswordException"
               path="/changePassword.jsp"/>
    </action>

    <!-- Save user registration -->
    <action    path="/saveRegistration"
               type="org.apache.struts.webapp.example.SaveRegistrationAction"
               name="registrationForm"
              scope="request"
              input="registration"/>

    <!-- Save mail subscription -->
    <action    path="/saveSubscription"
               type="org.apache.struts.webapp.example.SaveSubscriptionAction"
               name="subscriptionForm"
              scope="request"
              input="subscription">
      <forward name="subscription"    path="/subscription.jsp"/>
      <forward name="success"         path="/editRegistration.do?action=Edit"/>
    </action>


    <!-- Display the "walking tour" documentation -->
    <action    path="/tour"
            forward="/tour.wml">
    </action>
 <!--action    path="/tilesTest"
      type="org.apache.struts.actions.ForwardAction"
               forward="/main">
   <forward name="/main" path=".mainLayout"></forward>
    </action-->

  </action-mappings>


  <!-- ========== Controller Configuration ================================ -->

  <controller>
    <!-- The "input" parameter on "action" elements is the name of a
         local or global "forward" rather than a subapp-relative path -->
    <set-property property="inputForward" value="true"/>
  </controller>


  <!-- ========== Message Resources Definitions =========================== -->

  <message-resources
    parameter="org.apache.struts.webapp.example.ApplicationResources"/>


  <!-- ========== Plug Ins Configuration ================================== -->

  <plug-in className="org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn">
    <set-property property="pathname" value="/WEB-INF/database.xml"/>
  </plug-in>
  <plug-in className="org.apache.struts.tiles.TilesPlugin">
        <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
    </plug-in>
  <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames"
                     value="/WEB-INF/validator-rules.xml,
                            /WEB-INF/validation.xml"/>
  </plug-in>

</struts-config>


發佈了53 篇原創文章 · 獲贊 1 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章