DispatchAction样例

建一个jsp页面代码如下:

<%@ page language = "java" pageEncoding = "UTF-8" %>
<%@ taglib uri = "http://jakarta.apache.org/struts/tags-bean" prefix = "bean" %>
<%@ taglib uri = "http://jakarta.apache.org/struts/tags-html" prefix = "html" %>
<%@ taglib uri = "http://jakarta.apache.org/struts/tags-logic" prefix = "logic" %>
 
< html:html locale = "true" >
  < head >
    < html:base />
   
    < title > MyJsp.jsp </ title >
 
  </ head >
 
  < body >
< a href = "modify.do?method=add" > dfsd </ a >
< a href = "modify.do?method=update" > dfsd </ a >
  </ body >
</ html:html >
建一个 action 代码如下 : 注意:这里的 action 必须是继承 DispatchAction
 
package com.yourcompany.struts.action;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
 
/**
 * MyEclipse Struts
 * Creation date: 01-05-2007
 *
 * XDoclet definition:
 * @struts:action validate="true"
 */
public class ModifyAction extends DispatchAction {
 
    // --------------------------------------------------------- Instance Variables
 
    // --------------------------------------------------------- Methods
 
    /**
     * Method execute
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     */
    public ActionForward update( ActionMapping mapping,  ActionForm form,
        HttpServletRequest request,  HttpServletResponse response) {
System.out.print("update");
        // TODO Auto-generated method stub
        return null;
    }
    public ActionForward add( ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        System.out.print("add");
            // TODO Auto-generated method stub
            return null;
        }
}
Struts-config.xml 配置代码如下:
<? xml version = "1.0" encoding = "UTF-8" ?>
<! DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd" >
 
< struts-config >
  < data-sources />
  < form-beans />
  < global-exceptions />
  < global-forwards />
  < action-mappings >
    path = "/modify"
    parameter = "method"
    type = "com.yourcompany.struts.action.ModifyAction" />
  
  </ action-mappings >
  < message-resources parameter = "com.yourcompany.struts.ApplicationResources" />
</ struts-config >
注意:这里的 parameter=method 要和 jsp 页面连接问号后的变量一致
这样的点击add,update分别会在控制台上打出,add,update 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值