struts DispatchAction的使用

1、JSP页面
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Simple jsp page</title>
<script type="text/javascript">
function compute(param) {
document.forms[0].elements["method"].value = param;
document.forms[0].submit();
}
</script>
</head>
<body>
<html:form action="/login" method="post">
<input type="hidden" name="method"/>
<input type="submit" value="add++" onclick="compute('add')"/>
<input type="submit" value="sub--" onclick="compute('sub')"/>
</html:form>
</body>
</html>

2、struts-config.xml文件
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
<form-beans>
<form-bean name="login" type="struts.form.LoginForm"/>
</form-beans>

<action-mappings>
<action path="/login" type="struts.action.LoginAction" parameter="method" name="login">
<forward name="success" path="/success.jsp"/>
</action>
</action-mappings>
</struts-config>

3、Action页面
public class LoginAction extends DispatchAction {
public ActionForward add(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
System.out.println("add-----------------------");
return actionMapping.findForward("success");
}

public ActionForward sub(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
System.out.println("sub------------------------");
return actionMapping.findForward("success");
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值