1.修改struts2常量配置(3种)

第一种

在str/struts.xml中添加constant标签

 <struts>
<!-- 如果使用使用动态方法调用和include冲突 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- 开发者模式 -->
<constant name="struts.devMode" value="true" />
</struts>

第二种

src下新建一个struts.properties

struts.enable.DynamicMethodInvocation=true
struts.devMode=true

第三种

在web.xml 添加context-param标签
<context-param>
  <param-name>键</param-name>
  <param-value>值</param-value>
</context-param>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <context-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>UTF-8</param-value>
</context-param> </web-app>

2.常用的常量配置

struts.i18n.encoding=UTF-8
i18n 国际化 解决post提交乱码
 
struts.action.extension=action,,
指定访问action时的后缀名 默认为action和空
 
struts.devMode = false
指定struts2是否以开发模式运行
国际化可以不重启
struts.xml不需要重启就可以生效(热加载)
更多的错误信息提示
 
struts.enable.DynamicMethodInvocation = false
动态方法调用开启常量 默认是false 需要开启
 
如果想找更多的常量配置可以到struts2-core-2.3.20.jar->org.apache.struts2->default.properties里 面有strtus默认的常量配置
 
3.动态方法调用(2种)
方式一
第一步
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<!-- 配置动态方法调用是否开启常量 默认是关闭的,需要手动开启 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" /> <package name="dynamic" namespace="/dynamic" extends="struts-default">
<action name="Demo1Action" class="cn.zhr.Demo1Action">
<result name="success" type="dispatcher">hello.jsp</result>
</action>
</package>
</struts>

第二步 通过输入网站地址 要使用!跟方法名

http://localhost:8080/struts2_day01/dynamic/Demo1Action!add

方式二

利用通配符使用{来取出*号的内容}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>
<!-- 配置动态方法调用是否开启常量 默认是关闭的,需要手动开启 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" /> <package name="dynamic" namespace="/dynamic" extends="struts-default">
<action name="Demo1Action_*" class="cn.zhr.Demo1Action" method="{1}">
<result name="success" type="dispatcher">hello.jsp</result>
</action>
</package>
</struts>

http://localhost:8080/struts2_day01/dynamic/Demo1Action_add.action

4.action类详解

Action类的书写方式
方式一:
创建一个类,可以是POJO,不用继承任何父类,也不需要实现任何接口
是struts2框架的代码侵入性更低
public calss Demo3Action{}
 
方式二:
实现一个接口Action
里面有execute方法,提供action方法的规范
Action接口预置了一些字符串,可以返回结果时使用,为了方便
public class Demo4Action implements Action{
  @Override
  public String execute() throws Exception{
    return null;
  }
}
 
方式三:
继承一个类ActionSupport
帮我们实现了Action,Validateable,ValidationAware,TextProvider,LocaleProvider
如果我们需要使用到这些接口的实现时,不需要自己来实现了
public class Demo5Action extends ActionSupport{
 
}
 

Struts2-整理笔记(二)常量配置、动态方法调用、Action类详解的更多相关文章

  1. JAVAEE学习——struts2_01:简介、搭建、架构、配置、action类详解和练习:客户列表

    一.struts2是什么 1.概念 2.struts2使用优势以及历史 二.搭建struts2框架 1.导包 (解压缩)struts2-blank.war就会看到 2.书写Action类 public ...

  2. c# 把一个匿名对象赋值给一个Object类型的变量后,怎么取这个变量? c# dynamic动态类型和匿名类 详解C# 匿名对象(匿名类型)、var、动态类型 dynamic 深入浅析C#中的var和dynamic

    比如有一个匿名对象,var  result =......Select( a=>new {  id=a.id, name=a.name});然后Object  obj =  result ;我怎 ...

  3. struts2的action类详解

    Action类的书写方式 方式1

  4. JavaWeb_(Struts2框架)struts.xml核心配置、动态方法调用、结果集的处理

    此系列博文基于同一个项目已上传至github 传送门 JavaWeb_(Struts2框架)Struts创建Action的三种方式 传送门 JavaWeb_(Struts2框架)struts.xml核 ...

  5. Struts2学习笔记二 配置详解

    Struts2执行流程 1.简单执行流程,如下所示: 在浏览器输入请求地址,首先会被过滤器处理,然后查找主配置文件,然后根据地址栏中输入的/hello去每个package中查找为/hello的name ...

  6. 2018.12.15 struts.xml 一般配置文件写法 && 配置动态方法

    struts.xml 原始配置文件 配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE s ...

  7. struts2.5+框架使用通配符与动态方法

    概述:struts2.5以后加强了安全性,下面就是安全配置引发的问题 通配符: 在学习struts框架时经常会使用到通配符调用方法,如下: <package name="usercru ...

  8. struts2-环境搭建-访问流程-配置详解-常量配置-类详解

    1 struts2概述 1.1 概念  1.2 struts2使用优势 自动封装参数 参数校验 结果的处理(转发|重定向) 国际化 显示等待页面 表单的防止重复提交 struts2具有更加先进的架构以 ...

  9. 01_5_Struts_ActionMethod_DMI_动态方法调用

    01_5_Struts_ActionMethod_DMI_动态方法调用 1. ActionMethod_DMI_动态方法调用 Action执行的时候并不一定要执行execute()方法 可以在配置文件 ...

随机推荐

  1. Libevent 事件循环(1)

    // 事件的dispatch int event_base_loop(struct event_base *base, int flags) {    //得到采用的事件模型 epoll/epoll/ ...

  2. Nginx的知识分享,技术分享

    3. Nginx常用命令管理及升级 查看nginx进程 ps -ef|grep nginx 说明:nginx的进程由主进程和工作进程组成. 启动nginx nginx 启动结果显示nginx的主线程和 ...

  3. npm install 时报错 Unexpected end of input at 1:15930

    从github上clone代码后npm install,结果解决办法: npm config set registry https://registry.npm.taobao.org之后出现自动生成了 ...

  4. php IP转换整形(ip2long)

    如何将四个字段以点分开的IP网络址协议地址转换成整数呢?PHP里有这么一个函数ip2long.比如 <?php echo ip2long("10.2.1.3"); ?> ...

  5. 基于Spring Aop实现类似shiro的简单权限校验功能

    在我们的web开发过程中,经常需要用到功能权限校验,验证用户是否有某个角色或者权限,目前有很多框架,如Shiro Shiro有基于自定义登录界面的版本,也有基于CAS登录的版本,目前我们的系统是基于C ...

  6. pipelineDB初体验

    官网:http://www.pipelinedb.com/ pipelineDB是基于postgres的stream数据库.完全兼容pg的东西. 由于产品需要解决性能这块瓶颈,老大让试试这款基于流计算 ...

  7. 【机器学习】RNN学习

    感谢中国人民大学的胡鹤老师,课程容量巨大,收获颇丰. 之前提到的CNN模型主要用到人类的视觉中枢,但其有一劣势,无论是人类的视觉神经还是听觉神经,所接受到的都是一个连续的序列,使用CNN相当于割裂了前 ...

  8. MySQL InnoDB四个事务级别 与 脏读、不反复读、幻读

    MySQL InnoDB事务隔离级别脏读.可反复读.幻读 希望通过本文.能够加深读者对ySQL InnoDB的四个事务隔离级别.以及脏读.不反复读.幻读的理解. MySQL InnoDB事务的隔离级别 ...

  9. java.lang.IllegalStateException: attempt to re-open an already-closed object

    attempt to re-open an already-closed object 字面理解,试图再次打开已经关闭的对象.这是我在操作sqlited的时候出现的错误, 我在一个activity里面 ...

  10. OracleOraDb11g_home1TNSListener服务启动后停止,某些服务在未由其他服务或程序使用时将自己主动停止

    解决的方法,大家来分享一下 1:注冊表中 HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/services/OracleOraDb11g_home1TNSLis ...