⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 baseaction.java

📁 基本库存管理系统的框架 struts hibernate
💻 JAVA
字号:
package com.strong.ims.struts;

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;


import com.strong.ims.comutil.IConstants;
import com.strong.ims.comutil.exception.BaseException;
/**
 * 
 * @author 
 * Base action for developers
 */
public abstract class BaseAction extends Action {
	
	/**
	 * devloper using
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public abstract ActionForward doexecute (ActionMapping mapping, ActionForm form, 
			HttpServletRequest request, HttpServletResponse response) throws BaseException,Exception;
	
	/**
	 * main execute Method
	 */
	public ActionForward execute (ActionMapping mapping, ActionForm form, 
			HttpServletRequest request, HttpServletResponse response) 
		throws Exception {
		ActionErrors errors = new ActionErrors( ); //Struts消息对象 在视图中读取信息
		ActionForward forward = new ActionForward( );
		
		try {			
			forward = this.doexecute(mapping,form,request,response);
		}
		catch(BaseException e) {
			//使用编码处理异常
			//call the generic exception handler method
			this.processStrongExeption(errors,e);
			//save the errors in request
			this.saveErrors(request,errors);
			forward = mapping.findForward(IConstants.ERROR_PAGE);    //统一普通错误页面
			
			/**
			 * 使用配置处理异常
			 */
			//throw new  BaseException(e.getCause(),"",IConstants.ERROR_DAOPROCESS);
		}
		catch(Exception ex) {
			//call the generic exception handler method 
			//the unknown error
			ActionError errorUnkown = new ActionError(IConstants.ERROR_UNKOWN,ex.getMessage());
			errors.add(ActionErrors.GLOBAL_ERROR,errorUnkown);
			//save the errors in request
			this.saveErrors(request,errors);
			forward = mapping.findForward(IConstants.ERROR_PAGE);     //统一系统错误页面
			
		}
		
		return forward;
		
	}
	
	/**
	 * @param ActionMessages errors
	 * @param StrongException ex
	 */
	protected void processStrongExeption(ActionMessages errors,BaseException ex ) {
		//新的acionmessage
		ActionError error = null;
		
		//error code is the key to the resource bundle
		String errorCode = ex.getMessageKey();
		//error Str 
		String errorStr = ex.getMessageStr();
		//如果不为null 而且 不为空
		if( errorStr != null && errorStr.length() > 0 ) {
			error = new ActionError(errorCode,errorStr);
		}
		else {
			error = new ActionError(errorCode);
		}
		
		errors.add(ActionErrors.GLOBAL_ERROR, error);
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -