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

📄 adddvdaction.java

📁 用Struts实现的一个例子
💻 JAVA
字号:
//Created by MyEclipse Struts// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.1/xslt/JavaClass.xslpackage com.yourcompany.struts.action; import java.util.LinkedList;import java.util.List; import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;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.yourcompany.struts.form.AddDVDForm;import dvd.model.DVDLibrary;/**  * MyEclipse Struts * Creation date: 10-29-2006 *  * XDoclet definition: * @struts.action path="/addDVD" name="addDVDForm" input="/addDVD.jsp" scope="request" validate="true" * @struts.action-forward name="success" path="/success.jsp" * @struts.action-forward name="failure" path="/addDVD.jsp" */public class AddDVDAction extends Action {	// --------------------------------------------------------- Instance Variables	// --------------------------------------------------------- Methods	/** 	 * Method execute	 * @param mapping	 * @param form	 * @param request	 * @param response	 * @return ActionForward	 */	@SuppressWarnings("unchecked")	public ActionForward execute(		ActionMapping mapping,		ActionForm form,		HttpServletRequest request,		HttpServletResponse response) {		AddDVDForm addDVDForm = (AddDVDForm) form;		// 用于存放错误信息		List errorMsgs = new LinkedList();		try		{				int year = -1;			try			{				year = Integer.parseInt(addDVDForm.getYear());			}catch(NumberFormatException nfe)			{				errorMsgs.add("The 'year' field must be apositive integer.");			}						if((year != -1) && ((year < 2000 ) || (year > 2010)) )			{				errorMsgs.add("The 'year' field must within 2000 to 2010");			}			if( addDVDForm.getGenre().length() == 0)			{				errorMsgs.add("please input newgenre or genre");			}			if( addDVDForm.getTitle().length() == 0)			{				errorMsgs.add("Please enter the title of the league.");			}						if( !errorMsgs.isEmpty())			{				request.setAttribute("error",errorMsgs);				return mapping.findForward("failure");			}			// 创建对象			DVDLibrary libaray = new DVDLibrary();						libaray.createDVDItem(addDVDForm.getTitle(),					addDVDForm.getYear(),					addDVDForm.getGenre());						//addDVDForm.setGenre("中国人");						request.setAttribute("title",addDVDForm.getTitle());			request.setAttribute("year",addDVDForm.getYear());			request.setAttribute("genre",addDVDForm.getGenre());			return mapping.findForward("success");		}catch(RuntimeException e)		{			e.printStackTrace();			return mapping.findForward("failure");		}	}// end of meth}

⌨️ 快捷键说明

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