JPetStore5展示层分析
l Web.xml文件
 <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.shtml</url-pattern>
 </servlet-mapping>
表示action的扩展名为shtml
<security-constraint>
    <web-resource-collection>
      <web-resource-name>
        Restrict access to JSP pages
      </web-resource-name>
      <url-pattern>*.jsp</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <description>
        With no roles defined, no access granted
      </description>
    </auth-constraint>
 </security-constraint>
限制任何人直接访问jsp文件
l 系统入口
Index.html文件
含有下列超连接:<p><a href="shop/index.shtml">Enter the Store</a></p>
<action path="/shop/index" type="org.apache.struts.beanaction.BeanAction"
            name="catalogBean" parameter="*" validate="false">
      <forward name="success" path="/catalog/Main.jsp"/>
 </action>
转向/catalog/Main.jsp文件
注意:org.apache.struts.beanaction.BeanAction
这个类是被封装到beanaction.jar包的,由Clinton写的。
这个类与BaseBean的子类一起合作,把action和formbean整合在formbean一个类里。
并且action调用的方法就是formbean里定义的方法,依据actionmapping里的parameter参数值确定调用哪个方法。如果没有parameter参数,就调用名叫action配置值的函数。
靠setMessage报告消息给页面,只能支持一种语言。
因为没有action类,所以不能调用action的saveMessages和saveErrors方法。
缺点:不能防止重复提交action,即对Token的操作。
l ActionBean基类
此基类继承了ValidatorActionForm,所以,可以使用validator框架。
l Action配置
<action path="/shop/newAccountForm" type="org.apache.struts.beanaction.BeanAction"
            name="accountBean" scope="session" parameter="*"
            validate="false">
      <forward name="success" path="/account/NewAccountForm.jsp"/>
 </action>
由上面可以看到path的值是随便定义的,不必局限于/xxx一层。
l 界面重用
<html:form action="/shop/newAccount.shtml" method="post">
    <html:hidden name="accountBean" property="validation" value="new"/>
    <h3>User Information</h3>
    <table>
      <tr>
        <td>User ID:</td><td><html:text name="accountBean" property="username"/></td>
      </tr><tr>
      <td>New password:</td><td><html:password name="accountBean" property="password"/></td>
    </tr><tr>
      <td>Repeat password:</td><td><html:password name="accountBean" property="repeatedPassword"/></td>
    </tr>
    </table>
    <%@ include file="IncludeAccountFields.jsp" %>
    <input type="submit" name="submit" value="Create Account"/>
 </html:form>
l Get参数绑定actionBean
<html:link page="/shop/viewCategory.shtml?categoryId=FISH">
categoryID绑定到Category 类的categoryId属性
l ActionMapping的scope属性
属性值大多是不是session,为什么不是request? 
因为有下面的代码
<logic:present name="accountBean" scope="session">
        <logic:equal name="accountBean" property="authenticated" value="true" scope="session">
          <html:link page="/shop/signoff.shtml">Sign Out</html:link>
          <img align="middle" src="../images/separator.gif"/>
          <html:link page="/shop/editAccountForm.shtml">My Account</html:link>
        </logic:equal>
</logic:present>