Struts2之动态方法调用
1.感叹号
前台页面
<%@ 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>Insert title here</title>
</head>
<body>
<a href="user!login.action">登录</a><br>
<a href="user!register.action">注册</a>
</body>
</html>
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<package name="jiangwenwen" namespace="/" extends="struts-default">
<action name="user" class="cn.jiangwenwen.action.UserAction">
<result name="test">/test.jsp</result>
<allowed-methods>login,register</allowed-methods>
</action>
</package>
</struts>
Action方法
package cn.jiangwenwen.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport{
public String login() {
System.out.println("这是登陆!");
return "test";
}
public String register() {
System.out.println("这是注册!");
return "test";
}
}
2.通配符
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>Insert title here</title>
</head>
<body>
<a href="user_login.action">登录</a><br>
<a href="user_register.action">注册</a>
</body>
</html>
struts.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
<package name="jiangwenwen" namespace="/" extends="struts-default">
<!--使用通配符优化上面的步骤操作,{1}代表*第1次出现的位置-->
<action name="user_*" class="cn.jiangwenwen.action.UserAction" method="{1}">
<result name="test">/test.jsp</result>
<allowed-methods>login,register</allowed-methods>
</action>
</package>
</struts>
Struts2之动态方法调用的更多相关文章
- 第三篇——Struts2的动态方法调用
Struts2动态方法调用 默认方式:默认执行方法中的execute方法,若指定类中没有该方法,默认返回success: method方式:执行method属性中定义的方法,没有该方法,页面报错: 通 ...
- struts2的动态方法调用(DMI)和通配符映射
动态方法调用 1.Struts2默认关闭DMI功能,需要使用需要手动打开,配置常量 struts.enable.DynamicMethodInvocation = true 2.使用“!”方法,即 ...
- struts2之动态方法调用(转)
转自:http://blog.csdn.net/longwentao/article/details/6940289 当我们访问一个Action时,默认是访问execute()方法,但当在一个Acti ...
- Struts2中动态方法的调用
Struts2中动态方法调用就是为了解决一个action对应多个请求的处理,以免action太多. 主要有一下三种方法:指定method属性.感叹号方式和通配符方式.推荐使用第三种方式. 1.指定me ...
- Struts2之action 之 感叹号 ! 动态方法调用
struts2的动态方法调用的方式: 1.第一种方式:设置method属性 在Action类中定义一个签名与execute方法相同.只是名字不同的方法,如定义为: public String logi ...
- Struts2学习笔记 - Action篇<动态方法调用>
有三种方法可以使一个Action处理多个请求 动态方法调用DMI 定义逻辑Acton 在配置文件中使用通配符 这里就说一下Dynamic Method nvocation ,动态方法调用,什么是动态方 ...
- 第三章Struts2 Action中动态方法调用、通配符的使用
01.Struts 2基本结构 使用Struts2框架实现用登录的功能,使用struts2标签和ognl表达式简化了试图的开发,并且利用struts2提供的特性对输入的数据进行验证,以及访问Servl ...
- Struts2 动态方法调用
01.Struts 2基本结构 使用Struts2框架实现用登录的功能,使用struts2标签和ognl表达式简化了试图的开发,并且利用struts2提供的特性对输入的数据进行验证,以及访问Servl ...
- Struts2 Action中动态方法调用、通配符的使用
一.Struts2执行过程图: 二.struts2配置文件的加载顺序 struts-default.xml---struts-plugin.xml---struts.xml 具体步骤: 三.Actio ...
随机推荐
- python学习笔记(12):高级面向对象
一.__slots__和property 1.__slots__魔术函数动态的添加方法和属性 2.直接暴露属性的局限性 3.使用get/set方法 4.利用@property简化get/set方法 5 ...
- maven整合S2SH
1.pom.xml <?xml version="1.0"?> <project xsi:schemaLocation="http://maven.ap ...
- kali优化配置(1)
前言 无论是工具还是物理机.虚拟机,我都遇到过惨绝人寰的配置错误.为了有效避免这些烦恼困住我,写一个排错文档之外,我还应当谨慎小心,从每一次配置走起..我的kali昨日的MySQL无法登陆,也没办法联 ...
- rocketmq-console控制台管理界面配置
Rocketmq可视化管理控制台配置 前提: RocketMQ有一个对其扩展的开源项目incubator-rocketmq-externals,这个项目中有一个子模块叫“rocketmq-consol ...
- python基础--文件的操作
#r w a 文件读取操作 默认打开为读操作 #f=open('coldplay.txt','r',encoding="utf-8")#open函数默认已系统编码方式打开windo ...
- tac反向显示文件内容
1.命令功能 tac是cat的反向拼写功能是反向显示文件内容.cat是从文件第一行开始读取文件输出,tac是从最后一行开始读取文件并进行反向输出. 2.语法格式 tac [option] [fil ...
- j函数 判断以 什么开头
1.str.charAt(index) 返回字符串中指定位置的字符. str 是字符串 我们要将获得的数据 转化为字符串 var code = res.statusCode.toString(); ...
- JS基础入门篇(七)—运算符
1.算术运算符 1.算术运算符 算术运算符:+ ,- ,* ,/ ,%(取余) ,++ ,-- . 重点:++和--前置和后置的区别. 1.1 前置 ++ 和 后置 ++ 前置++:先自增值,再使用值 ...
- rest认证组件,权限组件,频率组件,url注册器,响应器组件,分页器组件
1.认证组件 1.1 认证组件利用token来实现认证 1.2 token认证的大概流程 用户登录===>获取用户名和密码===>查询用户表 如果用户存在,生成token,否则返回错误信息 ...
- 重写LayoutParams,读取子View自定义属性
在EasyConstraintLayout内部定义一个静态类LayoutParams继承ConstraintLayout.LayoutParams,然后在构造方法中读取上面自定义的属性.我们通过裁剪的 ...