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

📄 noticeaction.java

📁 数学网
💻 JAVA
字号:
//Created by MyEclipse Struts// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.1/xslt/JavaClass.xslpackage math.notice.controller;import java.util.List;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import javax.sql.DataSource;import math.login.model.User;import math.notice.dao.NoticeDAO;import math.notice.model.Notice;import org.apache.commons.beanutils.BeanUtils;import org.apache.commons.logging.LogFactory;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;/** * MyEclipse Struts Creation date: 11-20-2006 *  * XDoclet definition: *  * @struts.action parameter="ARTICLE" validate="true" * @struts.action-forward name="error" path="/sd_login.html" * @struts.action-forward name="success" path="/studentview.jsp" */public class NoticeAction extends Action {		private org.apache.commons.logging.Log __log = LogFactory.getFactory().    getInstance(this.getClass());private DataSource ds = null;	public ActionForward execute(		ActionMapping actionMapping,		ActionForm actionForm,		HttpServletRequest httpServletRequest,		HttpServletResponse httpServletResponse) {				ds=getDataSource(httpServletRequest);	    ActionForward myforward = null;	    String myaction = actionMapping.getParameter();	    // ds = getDataSource(httpServletRequest);	    if (isCancelled(httpServletRequest)) {	      if (__log.isInfoEnabled()) {		__log.info(" [Notice] " + actionMapping.getAttribute() +			   " - action was cancelled");	      }	      return actionMapping.findForward("cancel");	    }	    if (__log.isInfoEnabled()) {	      __log.info(" [Notice] action: " + myaction);	    }	    if ("".equalsIgnoreCase(myaction)) {	      myforward = actionMapping.findForward("failure");	    }	    else if ("NOTICEADD".equalsIgnoreCase(myaction)) {	      myforward = performAdd(actionMapping, actionForm, httpServletRequest,	httpServletResponse);	    }	    else if ("NOTICELIST".equalsIgnoreCase(myaction)) {	        myforward = performList(actionMapping, actionForm, httpServletRequest,	  httpServletResponse);	      }	    else if ("NOTICESHOW".equalsIgnoreCase(myaction)) {	        myforward = performShow(actionMapping, actionForm, httpServletRequest,	  httpServletResponse);	      }	    else if ("NOTICEUPDATE".equalsIgnoreCase(myaction)) {	        myforward = performUpdate(actionMapping, actionForm, httpServletRequest,	  httpServletResponse);	      }	    else if ("NOTICESAVE".equalsIgnoreCase(myaction)) {	        myforward = performSave(actionMapping, actionForm, httpServletRequest,	  httpServletResponse);	      }	    else if ("NOTICEDELETE".equalsIgnoreCase(myaction)) {	        myforward = performDelete(actionMapping, actionForm, httpServletRequest,	  httpServletResponse);	      }	    else {	      myforward = actionMapping.findForward("regerror");	    }	    return myforward;	  }	  private ActionForward performAdd(ActionMapping mapping,						ActionForm actionForm,						HttpServletRequest request,						HttpServletResponse response) {	    try {	    	NoticeDAO NoticeDAO = new NoticeDAO(ds);	    	HttpSession session = request.getSession();	      // 获得表单信息	      NoticeForm noticeForm = (NoticeForm) actionForm;	      // 实例花Reg;	   		      ds=getDataSource(request);	      Notice notice = new Notice();	      // 将noticeForm中的值赋给notice	      BeanUtils.populate(notice, BeanUtils.describe(noticeForm));	      notice.setUserid(((User)session.getAttribute("USER")).getId());	      notice.setUserip(request.getRemoteHost());	    	  NoticeDAO.insert(notice);	    	  return mapping.findForward("success"); }	    	  	    		// HttpSession session = request.getSession();		// session.setAttribute("REG", reg);	    	    	    catch (Exception e) {	      generalError(request, e);	      return mapping.findForward("failure");	    }	    	  }		// /////////////////////////////////////////////////////////////	private ActionForward performList(ActionMapping mapping,				ActionForm actionForm,				HttpServletRequest request,				HttpServletResponse response) {		try {			    HttpSession session = request.getSession();	        	String condition="";	        	String temp="";				NoticeDAO noticeDAO = new NoticeDAO(ds);				 	          int offset;	          int length =10;	              String pageOffset = request.getParameter("pager.offset");	              if (pageOffset == null || pageOffset.equals("")) {	                  offset = 0;	                  	                  NoticeSearchForm searchForm = (NoticeSearchForm) actionForm;	                  temp=searchForm.getCondition();	                  if (temp==null){	                	  temp="";	                  }	  				if (searchForm.getConditionid()==0){	  					condition="where Noticetitle like '%"+temp+"%' and Noticecontent like '%"+temp+"%'";	  						  				}else	  				if (searchForm.getConditionid()==1){	  					condition="where Noticetitle like '%"+temp+"%'";	  						  				}else	  				if (searchForm.getConditionid()==2){	  					condition="where Noticecontent like '%"+temp+"%'";	  						  				}	  					  			    session.setAttribute("CONDITION",condition);	  				              } else {	                  offset = Integer.parseInt(pageOffset);	                  condition=(String) session.getAttribute("CONDITION");	  				if (condition==null){	  					condition="";	  				}	              }	              	              List  Noticelist =(List) noticeDAO.list(offset, length, condition);	              int size = noticeDAO.getSize("notices",condition);	              String url = request.getContextPath() + mapping.getPath() + ".do";	              String pagerHeader = math.util.Pager.generate(offset, size, length, url);	              request.setAttribute("pagerHeader", pagerHeader);	              request.setAttribute("LIST", Noticelist);	              Notice notice =new Notice();	              	             // BeanUtils.populate(Notice, BeanUtils.describe(NoticeForm));	              session.setAttribute("notices",notice);		      return mapping.findForward("success");	}	catch (Exception e) {        generalError(request, e);        return mapping.findForward("failure");    }   }	  // //////////////////////////////////////////////////////////////	private ActionForward performShow(ActionMapping mapping,			ActionForm actionForm,			HttpServletRequest request,			HttpServletResponse response) {		 try {			 HttpSession session = request.getSession() ;			 NoticeDAO noticeDAO = new NoticeDAO(ds);		      int id=0;		    	String str_id = request.getParameter("id");		    	if(str_id!=null&&!str_id.equals(""))		    	{		    		id=Integer.parseInt(str_id);		    	}		    	else{			    	  return mapping.findForward("error");}		      //实例花Reg;		    	Notice Notice = noticeDAO.select(id);		      //将Reg中的值赋给regForm		     // BeanUtils.populate(NoticeForm, BeanUtils.describe(Notice));		      session.setAttribute("Notice", Notice);		     //将reg作为参数传给RegDAO中的insert函数		      return mapping.findForward("success");								    }		    catch (Exception e) {		      generalError(request, e);		      return mapping.findForward("failure");		    }	      }	/////////////////////////////////////////////////////	private ActionForward performUpdate(ActionMapping mapping,			ActionForm actionForm,			HttpServletRequest request,			HttpServletResponse response) {			try {				 HttpSession session = request.getSession() ;				 NoticeDAO noticeDAO = new NoticeDAO(ds);			      NoticeForm noticeForm = (NoticeForm) actionForm;			      int id=0;			    	String str_id = request.getParameter("id");			    	if(str_id!=null&&!str_id.equals(""))			    	{			    		id=Integer.parseInt(str_id);			    	}			    	else{				    	  return mapping.findForward("error");}			      //实例花Reg;			    	Notice Notice = noticeDAO.select(id);			      //将Reg中的值赋给regForm			     BeanUtils.populate(noticeForm, BeanUtils.describe(Notice));			     			     //将reg作为参数传给RegDAO中的insert函数			      return mapping.findForward("success");											    }			    catch (Exception e) {			      generalError(request, e);			      return mapping.findForward("failure");			    }	}	// /////////////////////////////////////////////////////////////////	  private ActionForward performSave(ActionMapping mapping,				ActionForm actionForm,				HttpServletRequest request,				HttpServletResponse response) {		  try {		    	NoticeDAO noticeDAO = new NoticeDAO(ds);		      		      // 获得表单信息		      NoticeForm noticeForm = (NoticeForm) actionForm;		      // 实例花Reg;		 			      ds=getDataSource(request);					      Notice Notice = new Notice();		      // 将RegForm中的值赋给reg		      BeanUtils.populate(Notice, BeanUtils.describe(noticeForm));		     		    	  noticeDAO.update(Notice);		    	 		    	  		    	  return mapping.findForward("success");		    			// HttpSession session = request.getSession();			// session.setAttribute("REG", reg);		   		    }		    catch (Exception e) {		      generalError(request, e);		      return mapping.findForward("failure");		    }}	  // /////////////////////////////////////////////////////////////////////	  private ActionForward performDelete(ActionMapping mapping,				ActionForm actionForm,				HttpServletRequest request,				HttpServletResponse response) {		  		  try {			  int id=0;		    	String str_id = request.getParameter("id");		    	if(str_id!=null&&!str_id.equals(""))		    	{		    		id=Integer.parseInt(str_id);		    	}		    	else{			    	  return mapping.findForward("error");}			  NoticeDAO noticeDAO = new NoticeDAO(ds);			  NoticeForm noticeForm = (NoticeForm) actionForm;		    		      //实例花Reg;			  Notice notice = new Notice();		      //将RegForm中的值赋给reg		     		      		      BeanUtils.populate(notice, BeanUtils.describe(noticeForm));		      //String username = regForm.getUsers_name();		     //将reg作为参数传给RegDAO中的insert函数		      notice.setNoticeid(id);		      noticeDAO.delete(notice);		    	  		    	  return mapping.findForward("success");		    }		    catch (Exception e) {		        generalError(request, e);		        return mapping.findForward("failure");		      }	}	  // /////////////////////////////////////////////////////////////	  private void sqlNullError(HttpServletRequest request, int result) {	    ActionErrors errors = new ActionErrors();	    if (result==1){	    errors.add("reg", new ActionError("error.reg.exist"));}	    if (result==2){	        errors.add("wrong", new ActionError("error.reg.pass"));}	    if (result==3){	        errors.add("relogin", new ActionError("error.reg.relogin"));}	    saveErrors(request, errors);	    if (__log.isErrorEnabled()) {	      __log.error(" [Reg] has not found - " + result);	    }	  }	  private void generalError(HttpServletRequest request, Exception e) {	    ActionErrors aes = new ActionErrors();	    aes.add(aes.GLOBAL_ERROR, new ActionError("error.general", e.getMessage()));	    saveErrors(request, aes);	    e.printStackTrace();	    if (__log.isErrorEnabled()) {	      __log.error(" [Reg] Error - " + e.getMessage());	    }	  }		// TODO Auto-generated method stub			}

⌨️ 快捷键说明

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