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之动态方法调用的更多相关文章

  1. 第三篇——Struts2的动态方法调用

    Struts2动态方法调用 默认方式:默认执行方法中的execute方法,若指定类中没有该方法,默认返回success: method方式:执行method属性中定义的方法,没有该方法,页面报错: 通 ...

  2. struts2的动态方法调用(DMI)和通配符映射

    动态方法调用   1.Struts2默认关闭DMI功能,需要使用需要手动打开,配置常量 struts.enable.DynamicMethodInvocation = true 2.使用“!”方法,即 ...

  3. struts2之动态方法调用(转)

    转自:http://blog.csdn.net/longwentao/article/details/6940289 当我们访问一个Action时,默认是访问execute()方法,但当在一个Acti ...

  4. Struts2中动态方法的调用

    Struts2中动态方法调用就是为了解决一个action对应多个请求的处理,以免action太多. 主要有一下三种方法:指定method属性.感叹号方式和通配符方式.推荐使用第三种方式. 1.指定me ...

  5. Struts2之action 之 感叹号 ! 动态方法调用

    struts2的动态方法调用的方式: 1.第一种方式:设置method属性 在Action类中定义一个签名与execute方法相同.只是名字不同的方法,如定义为: public String logi ...

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

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

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

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

  8. Struts2 动态方法调用

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

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

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

随机推荐

  1. V8引擎回收机制、 内存泄露

     一.垃圾回收:将内存不在使用的数据进行清理,释放内存空间   v8将内存分为新生代空间和老生代的空间   新生代空间:用于存活较短的对象   :又分为二个空间:from空间和to空间   :Scav ...

  2. css设置不允许复制文本内容

    之前做一个网上答题的页面时,考虑到要防止考生利用复制粘贴来提高作弊的可能性,就设计了不允许复制.方法也很简单,通过设置CSS 的 user-select就可以达到目的: -moz-user-selec ...

  3. wordpress系统网站访问慢的解决方案

    从2013年5月底开始,google在中国基本处于无法访问状态,谷歌官网 域名,香港域名均无法访问,就连之前的IP访问方法也都失效,而Google Adsense打不开,恐怕做谷歌联盟的站长也要倒霉了 ...

  4. linux安装 rsync 客户端和相关权限认证

    [root@rsync-client-inotify /]# yum install rsync -y [root@rsync-client-inotify /]# echo "redhat ...

  5. [BJWC2010]严格次小生成树(LCA,最小生成树)

    [BJWC2010]严格次小生成树 题目描述 小C最近学了很多最小生成树的算法,Prim算法.Kurskal算法.消圈算法等等.正当小C洋洋得意之时,小P又来泼小C冷水了.小P说,让小C求出一个无向图 ...

  6. vue 打包上线后 所使用的css3渐变属性丢失的问题解决方案

    最近在做vue项目的时候用到了css3渐变属性,本地跑项目没问题,但是打包放到服务器后发现这个属性丢失了.如下图: .join{ position:absolute; left:1rem; botto ...

  7. springboot 整合Druid

    Druid连接池监控配置 1) 引入依赖 <!-- https://mvnrepository.com/artifact/com.alibaba/druid --> <depende ...

  8. 路由Vue-router 的使用总结

    1.关于 router-view 匹配 vue 项目使用 vue-router,所有的根级别的路由都是在 App.vue 文件中的 router-view 中渲染的.比如下面的 path: '/' . ...

  9. Windows定时任务+bat文件+WinRar处理Mysql数据库的定时自动备份

    服务器环境 Windows Server 2003 ,服务器上采用的是IIS+mysql的集成工具phpStudy.MySQL的安装目录D:\phpStudy4IIS , WinRAR 安装目录 C: ...

  10. java并发编程如何预防死锁

    在java并发编程领域已经有技术大咖总结出了发生死锁的条件,只有四个条件都发生时才会出现死锁: 1.互斥,共享资源X和Y只能被一个线程占用 2.占有且等待,线程T1已经取得共享资源X,在等待共享资源Y ...