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

📄 petaction.java

📁 爱心”宠物诊所的职员需要使用系统提供的如下功能: 浏览诊所的兽医以及他们的专业特长; 浏览宠物的主人(即诊所的客户)的相关信息; 更新宠物的主人的相关信息; 向系统中增加一个新客户; 浏览宠
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.wzxy.web.struts.action;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;

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

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 org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;

import com.wzxy.business.IPetMgr;
import com.wzxy.business.PetMgrFactory;
import com.wzxy.dao.FenyeDao;
import com.wzxy.exception.DBException;
import com.wzxy.exception.PetOrOwnerNotExistsException;
import com.wzxy.pojos.Fenye;
import com.wzxy.pojos.PetDTO;

/** 
 * MyEclipse Struts
 * Creation date: 11-09-2007
 * 
 * XDoclet definition:
 * @struts.action path="/toPet" name="petForm" input="/petsearch.jsp" parameter="method" scope="request" validate="true"
 * @struts.action-forward name="success" path="petsearch_name.jsp"
 * @struts.action-forward name="failure" path="petsearch"
 */
public class PetAction extends DispatchAction {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward search(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DynaActionForm petForm = (DynaActionForm) form;
		IPetMgr service=PetMgrFactory.getInstance();
		Fenye fy=new Fenye();
		String sp=request.getParameter("showpage");
		if(sp==null || "".equals(sp))
		{
			sp="1";
		}
		try {
			fy=new FenyeDao().stuFenye(sp,petForm.getString("petName"),petForm.getString("ownerName"));
			ArrayList list= (ArrayList) service.PetSearch(petForm.getString("petName"),petForm.getString("ownerName"),fy);
		    request.setAttribute("petList",list);
		    request.setAttribute("fenye",fy);
		} catch (PetOrOwnerNotExistsException e) {
			ActionMessages errors=new ActionMessages();
			ActionMessage error=new ActionMessage("promt.petOrownerNOTExist");
			errors.add(ActionMessages.GLOBAL_MESSAGE,error);
			saveErrors(request,errors);
			return mapping.findForward("failure");
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return mapping.findForward("failure");
		}
		return mapping.findForward("success");
	}
	public ActionForward view(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DynaActionForm petForm = (DynaActionForm) form;
	    HttpSession session=request.getSession();
	    
	    int petId=Integer.parseInt(request.getParameter("petID"));
        String type=request.getParameter("toUpdatePage");
	    IPetMgr service=PetMgrFactory.getInstance();
	    try {
			PetDTO pet=service.selectPetById(petId);
			Calendar cal = new GregorianCalendar();
			cal.setTime(pet.getPetBirthDate());
			pet.setStrYear(String.valueOf(cal.get(Calendar.YEAR)));
			pet.setStrMonth(String.valueOf(cal.get(Calendar.MONTH) + 1)) ;
			pet.setStrDay(String.valueOf(cal.get(Calendar.DAY_OF_MONTH))) ;
			session.setAttribute("pet",pet);
			if(type!=null){
				ArrayList list=(ArrayList) service.selectPetTypes();
				session.setAttribute("types", list);
				return mapping.findForward("toUpdatePage");
			}else{
				return mapping.findForward("toPetView");
			}
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return mapping.findForward("failure");
		}
	
	}

}

⌨️ 快捷键说明

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