Struts2 通配符使用

Struts2通配符的使用可以在同一个Action中实现一个类别的(如学生管理) 增,删,改,查  方便项目后期的维护和查看。

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="alladd.action">添加数据</a><br/>
<a href="allupdate_updateSuccess.action">修改数据</a><br/>
<a href="alldelete.action">删除数据</a><br/>
<a href="allquery.action">查询数据</a><br/>

</body>
</html>

2.Action配置



import com.opensymphony.xwork2.ActionSupport;
import com.sun.org.apache.regexp.internal.recompile;

public class AllAction extends ActionSupport{

public String add(){
System.out.println("执行添加");
return "success";
}

public String update(){
System.out.println("执行修改");
return "updateSuccess";
}

public String delete(){
System.out.println("执行删除");
return "success";
}

public String query(){
System.out.println("执行查询");
return "success";
}

}

3.请求的控制转发struts.xml, <action name="all*" class="action.AllAction" method="{1}">其中all后面的*等于

上面jsp <a href="alladd.action">添加数据</a><br/>中alladd.action all后面的add。 {1}表示第一个通配符也就是add。

method="{1}"表示跳转到AllAction中对应的方法中

<?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>
<package name="mypackage" extends="struts-default">
<action name="all*" class="action.AllAction" method="{1}">
</action>
</package>
</struts>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值