Action执行的时候并不一定要执行execute方法
可以在配置文件中配置Action的时候用method=来指定执行那个方法,也可以在url地址中动态指定(动态方法调用DMI)(推荐)

动态方法调用的配置要先打开:

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

index.jsp

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首页</title>
</head>
<body>
<h1>Hello World~~~</h1>
Action执行的时候并不一定要执行execute方法<br>
可以在配置文件中配置Action的时候用method=来指定执行那个方法,也可以在url地址中动态指定(动态方法调用DMI)(推荐)<br>
<a href="user/userAdd">添加用户</a><br>
<a href="user/user!add">添加用户</a><br>
前者会产生太多的action,所以不推荐使用
</body>
</html>

struts.xml

 <?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.configuration.xml.reload" value="true"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true"/> <!-- namespace 必须 "/" 开头 -->
<package name="user" namespace="/user" extends="struts-default">
<action name="userAdd" class="com.bjsxt.struts2.user.action.UserAction" method="add">
<result>/user_add_success1.jsp</result>
</action> <action name="user" class="com.bjsxt.struts2.user.action.UserAction">
<result>/user_add_success.jsp</result>
</action>
</package> </struts>

UserAction

package com.bjsxt.struts2.user.action;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{

    private static final long serialVersionUID = -1735844624241755443L;

    public String add(){
return SUCCESS;
}
}

链接: http://pan.baidu.com/s/1skZG6Gd 密码: pxeb

ActionMethod_DMI_动态方法调用的更多相关文章

  1. 01_5_Struts_ActionMethod_DMI_动态方法调用

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

  2. Struts2学习笔记 - Action篇<动态方法调用>

    有三种方法可以使一个Action处理多个请求 动态方法调用DMI 定义逻辑Acton 在配置文件中使用通配符 这里就说一下Dynamic Method nvocation ,动态方法调用,什么是动态方 ...

  3. 第三章Struts2 Action中动态方法调用、通配符的使用

    01.Struts 2基本结构 使用Struts2框架实现用登录的功能,使用struts2标签和ognl表达式简化了试图的开发,并且利用struts2提供的特性对输入的数据进行验证,以及访问Servl ...

  4. Struts2 动态方法调用

    01.Struts 2基本结构 使用Struts2框架实现用登录的功能,使用struts2标签和ognl表达式简化了试图的开发,并且利用struts2提供的特性对输入的数据进行验证,以及访问Servl ...

  5. struts之动态方法调用使用通配符

    一.DMI动态方法调用的其中一种改变form表单中action属性的方式已经讲过了.还有两种,一种是改变struts.xml配置文件中action标签中的method属性,来指定执行不同的方法处理不同 ...

  6. struts之动态方法调用改变表单action属性

      一.动态方法调用(DMI:Dynamic Method Invocation) ⒈struts2中同样提供了这个包含多个逻辑业处理的Action,这样就可以在一个Action中进行多个业务逻辑处理 ...

  7. struts2DMI(动态方法调用)

    struts2动态方法调用共有三种方式: 1.通过action元素的method属性指定访问该action时运行的方法 <package name="action" exte ...

  8. Struts2 Action中动态方法调用、通配符的使用

    一.Struts2执行过程图: 二.struts2配置文件的加载顺序 struts-default.xml---struts-plugin.xml---struts.xml 具体步骤: 三.Actio ...

  9. Struts(八):动态方法调用

    动态方法调用:通过url动态调用action中的方法. 默认情况下,Struts的动态方法调用处于禁用状态. 测试定义一个action类: package com.dx.actions; public ...

随机推荐

  1. springboot整合mybatis,redis,代码(四)

    一 说明 这是spring整合redis注解开发的系类: 二 正文 在注解开发时候,会有这几个注解需要注意: 具体含义: 1.@Cacheable 可以标记在方法上,也可以标记在类上.当标记在方法上时 ...

  2. Visual Studio 2017 Key激活码

     Microsoft Visual Studio Enterprise 2017 企业版 KEY:NJVYC-BMHX2-G77MM-4XJMR-6Q8QFMicrosoft Visual Studi ...

  3. C语言变量:名称、地址和值

    变量的名称.地址和变量的值之间关系密切. 我们可以认为变量有两个属性:名称和值(其他属性暂不讨论): 计算机编译和加载后也认为变量有两个属性:地址和值.地址就是变量在计算机内部的名称. 许多语言中地址 ...

  4. Ubuntu server 修改系统时区

    执行命令: sudo dpkg-reconfigure tzdata

  5. Codeforces 277E

    按边建模,二叉树一条入边两条出边 判断就要用到mcmf的好处了 #include<bits/stdc++.h> using namespace std; const int maxn = ...

  6. fiddler抓包出现错误 creation of the root certificate was not successful

    fiddler安装完要配置才可以抓取HTTP 1.首先 找到Tools——>Options,在弹出的菜单中 选择https项 勾选捕捉https,这样配置完OK之后 一般会弹窗提示安装证书,点击 ...

  7. Spring Boot如何初始化数据

    Hibernate机制:classpath下的import.sql,l在ddl-auto是create和create-drop时自动执行,如果ddl-auto设置为update就不合适,所以此选项不适 ...

  8. 信息领域热词分析系统--python过滤

    利用python过滤去没用的词语,过滤的词语存储在停用文件中. #创建停用词表 def stopwordlist(): stopwords=[line.strip() for line in open ...

  9. leetcode 181 Employees Earning More Than Their Managers 不会分析的数据库复杂度

    https://leetcode.com/problems/employees-earning-more-than-their-managers/description/ 老师上课没分析这些的复杂度, ...

  10. Unity Screen Screen.currentResolution 当前分辨率

    The current screen resolution (Read Only). 当前屏幕的分辨率.(只读) If the player is running in window mode, th ...