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

📄 manageroperaction.java

📁 图书馆管理系统,用java编写,有原码,有检索,查询,修改,删除等功能
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.autumn.struts.action;

import java.io.UnsupportedEncodingException;
import java.util.List;

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

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.autumn.pojo.Manager;
import com.autumn.pojo.oper.Factory;

/** 
 * MyEclipse Struts
 * Creation date: 06-23-2008
 * 
 * XDoclet definition:
 * @struts.action path="/manageroper" name="manageroperForm" input="/form/manageroper.jsp" parameter="status" scope="request" validate="true"
 */
public class ManageroperAction extends DispatchAction {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	//增加管理员
	public ActionForward add(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DynaActionForm manageroperForm = (DynaActionForm) form;// TODO Auto-generated method stub
		ActionMessages errors = new ActionMessages() ;
		String mid = manageroperForm.getString("mid") ;
		String password1=manageroperForm.getString("password1") ;
		String password2=manageroperForm.getString("password2") ;
		String name=null;
		try {
			name = new String(manageroperForm.getString("name").getBytes("gbk"),"ISO8859-1");
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		if(mid==null||"".equals(mid))
		{
			errors.add("manageroper", new ActionMessage("id.null")) ;
			super.saveErrors(request, errors) ;
			return mapping.getInputForward() ;
		}
		if(password1==null||"".equals(password1))
		{
			errors.add("manageroper", new ActionMessage("password1.null")) ;
			super.saveErrors(request, errors) ;
			return mapping.getInputForward() ;
		}
		if(name==null||"".equals(name))
		{
			errors.add("manageroper", new ActionMessage("name.null")) ;
			super.saveErrors(request, errors) ;
			return mapping.getInputForward() ;
		}
		if(!(password1.equals(password2)))
		{
			errors.add("manageroper", new ActionMessage("password.err")) ;
			super.saveErrors(request,errors) ;
			return mapping.getInputForward() ;
		}
		if(Factory.getManagerOperIntance().queryById(mid)!=null)
		{
			errors.add("manageoper", new ActionMessage("manager.dub")) ;
			super.saveErrors(request, errors) ;
			return mapping.getInputForward() ;
		}
		Manager manager = new Manager() ;
		manager.setId(mid) ;
		manager.setPassword(password1) ;
		manager.setName(name) ;
		boolean suc = Factory.getManagerOperIntance().add(manager) ;
		if(suc)
		{
			return mapping.findForward("operinfo") ;
		}else
		{
			errors.add("manageroper", new ActionMessage("add.fail")) ;
			super.saveErrors(request, errors) ;
			return mapping.getInputForward() ;
		}
	}
	
	//删除管理员
	public ActionForward delete(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DynaActionForm manageroperForm = (DynaActionForm) form;// TODO Auto-generated method stub
		ActionMessages errors = new ActionMessages() ;
		String id = manageroperForm.getString("mid") ;
		if(id==null||"".equals(id))
		{
			errors.add("mdel", new ActionMessage("id.null")) ; ;
			super.saveErrors(request, errors) ;
			return mapping.getInputForward() ;
		}
		if(Factory.getManagerOperIntance().queryById(id)==null)
		{
			errors.add("mdel", new ActionMessage("manager.null")) ;
			super.saveErrors(request, errors) ;
			return mapping.getInputForward() ;
		}
		Manager manager = Factory.getManagerOperIntance().queryById(id) ;
		boolean suc = Factory.getManagerOperIntance().delete(manager) ;
		if(suc)
		{
			return mapping.findForward("operinfo") ;
		}else{
			errors.add("mdel", new ActionMessage("delete.fail")) ;
			super.saveErrors(request, errors) ;
			return mapping.getInputForward() ;
		}
	}
	//查看所有管理员信息
	public ActionForward queryall(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DynaActionForm manageroperForm = (DynaActionForm) form;// TODO Auto-generated method stub
		List all = null ;
		all = Factory.getManagerOperIntance().queryAll();
		request.setAttribute("all", all) ;
		return mapping.findForward("managerlist");
	}
	public ActionForward reset(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		DynaActionForm manageroperForm = (DynaActionForm) form;// TODO Auto-generated method stub
		String p1 = manageroperForm.getString("password1") ;
		String p2 = manageroperForm.getString("password2") ;
		if(p1==null||"".equals(p1))
		{
			request.setAttribute("passwordnull", "yes") ;
		}else if(!(p1.equals(p2)))
		{
			request.setAttribute("notequals", "yes") ;
		}else 
		{
			Manager m = (Manager)request.getSession().getAttribute("manager") ;
			m.setPassword(p1) ;
			boolean suc = Factory.getManagerOperIntance().update(m) ;
			if(suc)
			{
				request.setAttribute("suc", "yes") ;
			}else
			{
				request.setAttribute("suc", "no") ;
			}
		}
		request.setAttribute("reset", "yes") ;
		return mapping.findForward("mreset");
	}
}

⌨️ 快捷键说明

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