zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    AngularJS Insert Update Delete Using PHP MySQL
    Simple task manager application using AngularJS PHP MySQL
    AngularJS MySQL and Bootstrap Shopping List Tutorial
    Starting out with Node.js and AngularJS
    AngularJS CRUD Example with PHP, MySQL and Material Design
    How to install KVM on Fedora 22
    Fake_AP模式下的Easy-Creds浅析
    河南公务员写古文辞职信
    AI
    政协委员:最大愿望是让小学生步行上学
  • 原文地址:https://www.cnblogs.com/fanglove/p/2853323.html
Copyright © 2011-2022 走看看