• Struts2笔记2


    1.为Action属性注入值,在action中定义属性,get和set方法,在xml中配置如下,在页面上用${message}及可以得到注入的值

    <action name="list" class="cn.itcast.action.helloworld" method="execute">
                <param name="message">123456</param>
                <result name="SUCCESS">/WEB-INF/pages/helloworld.jsp</result>
            </action>

    2.默认情况下用.action后缀访问action,可以通过变量进行修改,如下:只处理.do和.action后缀的请求

    <struts>
        <constant name="struts.action.extension" value="do,action"></constant>
        <package name="itcast" namespace="/test" extends="struts-default" >
         </package>
    </struts>

      常量可以配置在好多文件中,如:struts.properties,加载的顺序是:  

    struts-default.xml
    struts-plugin.xml
    struts.xml
    struts.properties
    web.xml

      多个文件中配置了同一个常量,则后一个文件中配置的常量会覆盖前面文件中配置的常量

    3.struts2的处理流程:

      用户请求----->StrutsPrepareAndExecuteFilter----->Interceptor----->Action---->Result------->Jsp/html

      与struts1不同,struts2对用户的每一次请求都会创建一个Action,所以struts2中的Action是线程安全的。

    4.为了不让struts.xml配置文件太臃肿,把它分模块写到不同的xml文件中,然后再struts.xmlZ中用include包含进来

    <struts>
        <constant name="struts.action.extension" value="do,action"></constant>
        <include file="struts-user.xml"></include>
    </struts>

     5.如何在请求路径中动态指定action调用的方法:

      1)动态方法调用:在路径中的action后面加“!”+方法名+后缀

      如:http://localhost:8080/struts2/test/list!add.do

      2)利用通配符定义action,method为{1}代表“*”的内容,class里也可以使用,jsp路径也可以使用

    <package name="itcast" namespace="/test" extends="struts-default" >
            <action name="list_*" class="cn.itcast.action.helloworld" method="{1}">
                <result name="SUCCESS">/WEB-INF/pages/helloworld.jsp</result>
            </action>
         </package>
  • 相关阅读:
    LeetCode解题报告—— Permutations & Permutations II & Rotate Image
    LeetCode解题报告—— Combination Sum & Combination Sum II & Multiply Strings
    LeetCode解题报告—— Search in Rotated Sorted Array & Search for a Range & Valid Sudoku
    顺利通过EMC试验(2)
    CSS复合选择器
    Emmet快速生成HTML和CSS
    Spring 三种创建Bean的方式
    Spring BeanFactory和ApplicationContext的区别
    Spring ApplicationContext的三个实现类详解
    CSS的引入方式
  • 原文地址:https://www.cnblogs.com/fanglove/p/2853323.html
Copyright © 2020-2023  润新知