您的位置:首页 >> 编程开发 >> Java >> Struts/Hibernate >> 正文
Struts/Hibernate RSS
 

struts 2 学习相关

http://www.rdxx.com 08年06月19日 00:00 我要投稿

标签: Struts , 学习
 

    2 Constant 的配置。主要是对struts2 应用项目的一个全局配置,配合web。xml里配置Constants provide a simple way to customize a Struts application by defining key settings that modify framework and plugin behavior. There are two key roles for constants. First, they are used to override settings like the maximum file upload size or whether the Struts framework should be in "devMode" or not, and so on. Second, they specify which Bean implementation, among multiple implementations of a given type, should be chosen. Constants can be declared in multiple files. By default, constants are searched for in the following order, allowing for subsequent files to override previous ones:In the various XML variants, the constant element has two required attributes: name and value. Attribute  Required  Description  name  yes  the name of the constant  value  yes  the value of the constant In the struts.properties file, each entry is treated as a constant.In the web.xml file, any FilterDispatcher initialization parameters are loaded as constants.Sample usage Constant Example (struts.xml)<struts>

      <constant name="struts.devMode" value="true" />

      ...

    </struts>

 

    Constant Example (struts.properties)

    struts.devMode = true

 

    Constant Example (web.xml)

    <web-app id="WebApp_9" version="2.4"
     xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

        <filter>
            <filter-name>struts</filter-name>
            <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
            <init-param>
             <param-name>struts.devMode</param-name>
             <param-value>true</param-value>
            </init-param>
        </filter>

        ...

    </web-app>


    4.Namespace 的配置就是命名空间的配置 说白了就是你访问action 的前置url 有个默认空间 当你制定的空间找不到 就转到default里<package name="default">
        <action name="foo" class="mypackage.simpleAction">
            <result name="success" type="dispatcher">greeting.jsp</result>
        </action>

        <action name="bar" class="mypackage.simpleAction">
            <result name="success" type="dispatcher">bar1.jsp</result>
        </action>
    </package>

    <package name="mypackage1" namespace="/">
        <action name="moo" class="mypackage.simpleAction">
            <result name="success" type="dispatcher">moo.jsp</result>
        </action>
    </package>

    <package name="mypackage2" namespace="/barspace">
        <action name="bar" class="mypackage.simpleAction">
            <result name="success" type="dispatcher">bar2.jsp</result>
        </action>
    </package>
    5 include的配置
    你可以将配置分割成多个
    <!DOCTYPE struts PUBLIC
      "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
      "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>
        <include file="Home.xml"/>
        <include file="Hello.xml"/>
        <include file="Simple.xml"/>
        <include file="/util/POJO.xml"/>
        <include file="/com/initech/admin/admin-struts.xml"/>
    </struts>

    6 interceptors的配置
    对拦截类的配置 还有堆栈 堆栈里有对个拦截 就是这个意思
    <interceptors>
      <interceptor name="security" class="com.company.security.SecurityInterceptor"/>
      <interceptor-stack name="secureStack">
        <interceptor-ref name="security"/>
        <interceptor-ref name="defaultStack"/>
      </interceptor-stack>
    </interceptors>

    7 Action 的配置 这个比较关键 也比较常用。与struts 1 的不同就是 这个action 把原来的action和form 都包含了
       (1) action mapping  就是action类的对应名字
    <action name="Logon" class="tutorial.Logon">
      <result type="redirectAction">Menu</result>
      <result name="input">/Logon.jsp</result>
    </action>
       (2) Action Methods
     默认是execute的方法,可以通过method参数访问多个action的方法,即 action可以有多个方法 可以扩展

    <action name="delete" class="example.CrudAction" method="delete">
    即时访问这个类的delete方法
    Wildcard Method

    <action name="*Crud" class="example.Crud" method="{1}">

    即时访问deleteCrud 访问deleteCrud 方法
    即时访问eCrud 访问eCrud 方法
    如此对应
     (3) action default
     <package name="Hello" extends="action-default">

        <default-action-ref name="UnderConstruction">

        <action name="UnderConstruction">
            <result>/UnderConstruction.jsp</result>
        </action>

       (4) action wilddefault
    <action name="*">
      <result>/{1}.jsp</result>
    </action>
       (5 )  扩展映射
     <!-- Generic edit* mapping -->
    <action
        name="/edit*"
        class="org.apache.struts.webapp.example.Edit{1}Action">
        <result
            name="failure"
            path="/mainMenu.jsp"/>
        <result
            path="/{1}.jsp"/>
    </action>


    <action name="List*s" class="actions.List{1}s">
      <result>list{1}s.jsp</result>
    </action>

    <action name="ListSpons" class="actions.ListSpons">
      <result>listSpons.jsp</result>
    </action>

 

    Wildcard patterns can contain one or more of the following special tokens:
    * Matches zero or more characters excluding the slash ('/') character. ** Matches zero or more characters including the slash ('/') character. \character The backslash character is used as an escape sequence. Thus '\*'matches the character asterisk ('*'), and '\\'matches the character backslash ('\').

 

 


 

共3页  第1页 第2页 第3页


 
 
打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站