zoukankan      html  css  js  c++  java
  • Struts2-学习笔记系列(2)-常量配置和实现action

    1.常量配置

    在struts配置文件中,下面突出部分,就是常量配置。

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

    除了可以在struts.xml中、web.xml中配置常量外,还可以新建properties文件来管理常量。

    可以在properties文件中定义那些struts2有效的常量呢?

    解压:struts2-core-2.3.16.3.jar文件,找到里面的default.properties 文件可查看详细

    通常,Struts2按以下顺序搜索常量:

    struts-default.xml  在 core文件中

    struts-plugin.xml 在插件文件中

    struts.xml  应用中web,默认的struts2配置文件

    properties文件

    web.xml文件

    注意:一个常量配置文件中可以include另一个配置文件

    2.实现action

    Struts2不要求一定要实现或继承任何类型如actionsupport等,但原则上应该包含一个无参数的execute方法。同时,对于请求参数的封装,至少需要提供对应参数的get和set方法。当然,对于非请求参数,例如:action需要传递参数到下一个页面,也需要为其提供get和set方法。例如:

     1 public String execute() throws Exception {
     2 
     3     setTip("测试action包装变量");
     4 
     5     if (getUser().equals("zcx")) {
     6 
     7         ActionContext.getContext().getSession().put("user", getUser());
     8 
     9         return "success";
    10 
    11     }
    12 
    13     return "error";
    14 
    15 }
    16 
    17 
    18 
    19 public String getTip() {
    20 
    21     return tip;
    22 
    23 }
    24 
    25 
    26 
    27 public void setTip(String tip) {
    28 
    29     this.tip = tip;
    30 
    31 }
  • 相关阅读:
    从相册中获取图片
    Android中bitmap的相关处理
    Sublime Text的使用代码块安装的模块
    angular之控制器(0)
    13.程序集篇
    12.序列化与反序列篇
    11.泛型篇
    10.集合篇
    9.多态篇
    8.继承篇
  • 原文地址:https://www.cnblogs.com/zijiyanxi/p/5559667.html
Copyright © 2011-2022 走看看