zoukankan      html  css  js  c++  java
  • Struts2中的变量

    1     <package name="mypackage" extends="struts-default">
    2         <global-results>
    3         <result name="error">/success.jsp</result>
    4         </global-results>

    其它包 extends="mypackage" 就可以用到它里面的参数了

    常量

    1     <constant name="struts.devMode" value="true"></constant>
    2     <constant name="struts.i18n.encoding" value="UTF-8"></constant><!-- 相当于HttpServletRequest.setCharacterEncoding("UTF-8") -->
    3     <constant name="struts.action.extension" value="action,,do"></constant><!-- Struts2框架实际要处理的后缀 -->
    4     <constant name="struts.serve.static.browserCache" value="false"></constant><!-- 静态资源是否需要缓存,开发阶段最好改成false -->
    5     <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant><!--禁用动态方法调用 -->
    6     <constant name="struts.multipart.maxSize" value="52428800"></constant>      <!-- 限制文件大小-->

    struts2中每个请求都局部创建一个变量执行的,所以是线程安全的

    <include file=""></include>导入其他文件的 配置,为了解决action配置太多 看的花

    struts.xml中关闭动态调用 ,!后面就是动态调用

    //(不建议使用)动态方法调用:http://localhost:8080/struts2day02/customer/addCustomer!updateCustomer(应该执行addCustomer,使用!updateCustomer,在请求addCustomer就执行了updateCustomer)
    //关闭动态调用的功能:struts.enable.DynamicMethodInvocation = false

        <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>

    {1}代表前面的*

    1         <action name="orders_*" class="cn.itcast.action.OrdersAction" method="{1}">
    2             <result type="dispatcher" name="success">/orders/{1}.jsp</result>
    3             <result type="dispatcher" name="input">/orders/{1}.jsp</result>
    4         </action>
    5         <!-- 
    6         当访问http://localhost:8080/struts2day02/orders/orders_add动作时,就去调用add方法,并且转向add.jsp页面。因为使用了通配符。
    7          -->

     struts 会根据 变量是否存在,如果不存在会创建一个实例变量 并且赋值。例如

    public class Customer

    {

      String id;

         Address  a;

    set()get()省略

    }

    框架会new出 Address并且赋值

    jsp中 <input type="radio" name="hobby" value="吃饭">

    jsp中 <input type="radio" name="hobby" value="睡觉">

    类设计中class

    String[]hobby;

    ActionContext.getContext() 可以用于获取Action上下文

  • 相关阅读:
    springboot jpa 的使用
    《 mysiteforme 》 学习之wangEditor的使用
    《 mysiteforme 》 学习之layui table 的使用
    《 mysiteforme 》 学习之数据字典的使用
    Shiro + redis + 登录 + 记住我 + 验证码 + 登出(mysiteforme)
    spring boot 使用kindeditor上传传照片到nginx
    easypoi excel 文件导入导出
    猜年龄
    Kth number
    乌龟棋
  • 原文地址:https://www.cnblogs.com/friends-wf/p/3765725.html
Copyright © 2011-2022 走看看