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 ...
随机推荐
- Angular.js 使用$http的response得到的phone属性为undefined
这是个坑~ 先说解决方案:把response打印出来找你的属性 记录一下,经验不足,有些东西想当然了,所有错误出现都应该一步步去排查!!!切记想当然的自以为. 源码: js $scope.phone= ...
- es6 promise 结束回调地狱
promise的三种状态: pending---进行中 fulfiled---执行成功 rejected---执行失败 var promise = new Promise(function(resol ...
- [转]使用flask实现mock server
什么是mock server: http://www.testclass.net/interface/mock_server 使用flask 实现 mock server : http://www. ...
- 2018-8-28-win10-uwp-MVVM入门
title author date CreateTime categories win10 uwp MVVM入门 lindexi 2018-08-28 15:37:52 +0800 2018-2-13 ...
- Installation of the latest version of netease-cloud-music on Fedora 30 linux platform
Installation of the latest version of netease-cloud-music on Fedora 30 linux platform Abtract As we ...
- ASPOSE的示例下载地址
ftp://112.124.7.170/ASPOSE/Aspose.Words_16.3.0.zip http://blog.163.com/haolongqin@126/blog/static/10 ...
- PTA 错题记录
程设期中考, 记录一下曾经做错的选择填空. 1. 2. 3. 4. 5. 6.
- re模块 时间模块
# 正则模块'''正则就是用一些具有特殊含义的符号组合到一起用来描述字符或字符串的方法或者说,正则就是用来描述一类事物的规则它内嵌在python中,并通过re模块实现正则表达式模式被编译成一系列的字节 ...
- 使用django 的cache设置token的有效期
from rest_framework.authentication import BaseAuthentication from rest_framework.exceptions import A ...
- js中关键字 const , let , var 的用法区别
1.const定义的变量不可以修改,而且必须初始化. 2.var定义的变量可以修改,如果不初始化会输出undefined,不会报错. 3.let是块级作用域,函数内部使用let定义后,对函数外部无影响 ...