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 ...
随机推荐
- window.onload和document.ready的区别
window.onload和document.ready虽然两个方法的运行效果都一样,但他们之间是存在着区别的: 一.从执行的时间 window.onload在dom文档结构加载完毕以后就可以执行,不 ...
- 2018-8-10-C#-ValueTuple-原理
title author date CreateTime categories C# ValueTuple 原理 lindexi 2018-08-10 19:16:52 +0800 2018-2-13 ...
- python基础--内置函数map
num_1=[1,2,10,5,3,7] # num_2=[] # for i in num_1: # num_2.append(i**2) # print(num_2) # def map_test ...
- bzoj4811 [Ynoi2017]由乃的OJ 树链剖分+贪心+二进制
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4811 题解 我现在为什么都写一题,调一天啊,马上真的退役不花一分钱了. 考虑这道题的弱化版 N ...
- ThinkPhp view 路径用到的常量 __STATIC__ __JS__ __CSS__等
https://www.edoou.com/articles/1556848583530922 ThinkPHP5.1 里面__PUBLIC__无法生效的问题 在用PHP模板的时候需要引用外部的样式文 ...
- (arm板子tensorflow安装)armv7板子pip安装的wheel
树莓派之类的armv7板子在,安装 numpy,scipy时经常失败,因为安装过程是下载源码包到本地编译,然后再安装的,编译过程中往往就会失败. https://www.piwheels.org/si ...
- redis下载及安装教程
https://blog.csdn.net/w546097639/article/details/88547486
- iOS10以上App请求用户授权系统设置权限
<key>NSAppleMusicUsageDescription</key> <string>使用媒体资源</string> <key>N ...
- B/S大文件断点续传
一. 功能性需求与非功能性需求 要求操作便利,一次选择多个文件和文件夹进行上传:支持PC端全平台操作系统,Windows,Linux,Mac 支持文件和文件夹的批量下载,断点续传.刷新页面后继续传输. ...
- yum源更换
折腾了半天,怀疑自己能力 的时候,发现原来不是我的错.树莓派换源国内的aliyun,163都不能用,最好找到这个 # CentOS-Base.repo # # The mirror system us ...