扩展Action的一种

package com.foxconn.web.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.foxconn.web.form.BasicForm;

import com.foxconn.util.Exception.FoxconnException;

 /**
  * @author User
  */

public abstract class BasicAction extends  Action
{
   
    public Logger logger = Logger.getLogger(BasicAction.class);
   
    /**
     * @throws FoxconnException
     *
     */
    public ActionForward execute(ActionMapping mapping,
                         ActionForm form,
                         HttpServletRequest request,
                         HttpServletResponse response
                         )
     throws IOException,ServletException, FoxconnException
    {
        ActionForward forward = null;
       
        HttpSession session = request.getSession(false);
        if(session == null) session = request.getSession(true);
       
        System.out.println("mapping path:" + mapping.getPath());
       
        BasicForm baseForm = (BasicForm)form;       
        String action = baseForm.getAction();

        if(action == null) action = "";
       
        try
        {
            System.out.println("...ready to call [performAction]:action is " + action + " ...");
            forward = performAction(mapping, form, request, response, session, action); 
          
            if (forward == null)
//             System.out.println("foward is:"+forward);
//             System.out.println("mappings:"+mapping.getInputForward());
                forward = mapping.getInputForward();
            System.out.println("...successfully called [performAction] and return " + forward.getName() + "...");
           
        }
        catch(FoxconnException e)
        {
            e.printStackTrace();
            forward = mapping.getInputForward();
        }
        return forward;
    }   
    public abstract ActionForward performAction(ActionMapping mapping,
                                                  ActionForm form,
                                                  HttpServletRequest request,
                                                  HttpServletResponse response,
                                                  HttpSession session, String action)
     throws IOException, ServletException, FoxconnException;
 
    public abstract void InitMenu(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response,
            HttpSession session, String action)
throws IOException,ServletException,FoxconnException;
}

使用该action:

package com.foxconn.web.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.foxconn.web.bean.EmpBean;
import com.foxconn.web.de.Delegate;

import com.foxconn.util.Exception.FoxconnException;

import com.foxconn.web.form.ListEmpForm;

public class ListEmpAction extends BasicAction {
 
 //Logger logger = Logger.getLogger(ListEmpAction.class);
 
 /**
  * Method execute
  * @param ActionMapping mapping
  * @param ActionForm form
  * @param HttpServletRequest request
  * @param HttpServletResponse response
  * @return ActionForward
  * @throws Exception
  */
 public ActionForward performAction(ActionMapping mapping,
   ActionForm form,
   HttpServletRequest request,
   HttpServletResponse response,
   HttpSession session,
   String action)
 throws IOException, ServletException, FoxconnException {
  ListEmpForm empForm = (ListEmpForm) form; 
  Delegate delegeate = Delegate.getInstance();
  empForm.setEmpList(delegeate.getEmpInHmd());
  
  if(action.equals("addemp")){
   return mapping.findForward("addEmp");
  }
  
  else if(action.equals("delEmp")){
   EmpBean empbean = new EmpBean();
   empbean.setEmpNo(empForm.getId());
   delegeate.delEmp(empbean);
   empForm.setEmpList(delegeate.getEmpInHmd());
   return (mapping.getInputForward());
  }
  
  else  if(action.equals("modifyjs")){
   System.out.println("the id is:"+empForm.getId());
   EmpBean empbean = new EmpBean();
   empbean.setEmpNo(empForm.getId());
   EmpBean bean = delegeate.getEmpByEmpNo(empbean);
   session.setAttribute("empbean", bean);
   return mapping.findForward("mod");   
  }
  else return mapping.getInputForward();
 }

 public void InitMenu(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response,
    HttpSession session,
    String action
   ) throws IOException, ServletException {
  // TODO Auto-generated method stub
  
 }
}

不知不觉又贴了这么多代码上来,我看过一个网上媒体商店的code 没有用taglib

然后控制好像也不是很好使用 以上通过扩展action 我觉得从控制转向上好用多了

问题就是JSP页面得写一些脚本,而在JSP写脚本不正是趋势吗?:)比如Ajax

^_^

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值