action 动态方式

在这里插入图片描述

<%@ 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>
<h1>Action 的访问</h1>
<h3>通过method方式</h3>
<a href="${ pageContext.request.contextPath}/userFind.action">查询用户</a>
<a href="${ pageContext.request.contextPath}/userUpdate.action">修改用户</a>
<a href="${ pageContext.request.contextPath}/userDelete.action">删除用户</a>
<a href="${ pageContext.request.contextPath}/userSave.action">保存用户</a>

<h3>通过通配符的方式</h3>
<a href="${ pageContext.request.contextPath}/product_find.action">查询商品</a>
<a href="${ pageContext.request.contextPath}/product_update.action">修改商品</a>
<a href="${ pageContext.request.contextPath}/product_delete.action">删除商品</a>
<a href="${ pageContext.request.contextPath}/product_save.action">保存商品</a>


<h3>通过动态方法访问 的方式</h3>
<a href="${ pageContext.request.contextPath}/customer!find.action">查询客户</a>
<a href="${ pageContext.request.contextPath}/customer!update.action">修改客户</a>
<a href="${ pageContext.request.contextPath}/customer!delete.action">删除客户</a>
<a href="${ pageContext.request.contextPath}/customer!save.action">保存客户</a>


</body>
</html>

在这里插入图片描述


<?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>
<!-- 开启动态方法访问 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>

   
    <package name="default" namespace="/" extends="struts-default">
    <global-results>
           <result name="success">/hello.jsp</result>
    </global-results>

        <action name="userFind" class="cn.hello01.UserAction" method="find"></action>
        <action name="userSave" class="cn.hello01.UserAction" method="save"></action>
        <action name="userDelete" class="cn.hello01.UserAction" method="delete"></action>
        <action name="userUpdate" class="cn.hello01.UserAction" method="update"></action>  
        <action name="login" class="cn.hello01.helloAction" method=""></action>  
        <action name="login2" class="cn.hello01.helloAction2" method=""></action>  
        <action name="login3" class="cn.hello01.helloAction3" method=""></action>  
        
        <!-- 通配符的方式 -->
        <action name="product_*" class="cn.hello01.ProductAction" method="{1}"></action>
        
        <!-- 动态方法访问的方式 -->
        <action name="customer" class="cn.hello01.CustomerAction"></action>
        
    </package>
</struts>

在这里插入图片描述

package cn.hello01;

import com.opensymphony.xwork2.ActionSupport;

public class CustomerAction extends ActionSupport{
	public String find(){
		System.out.println("查询客户");
		return NONE;
	}
	public String save(){
		System.out.println("保存客户");
		return NONE;
	}
	public String delete(){
		System.out.println("删除客户");
		return NONE;
	}
	public String update(){
		System.out.println("更新客户");
		return NONE;
	}
}


在这里插入图片描述

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值