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

📄 sm_levelinfoservlet.java

📁 J2ee开发的 人事管理系统 使用oracle数据库 myeclips平台开发
💻 JAVA
字号:
package com.galaxy.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

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

import com.galaxy.vo.LevelInfoVO;
import com.galaxy.dao.LevelInfoDAO;
import com.galaxy.dao.UserInfoDAO;

public class SM_LevelInfoServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public SM_LevelInfoServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
		response.setCharacterEncoding("gb2312");
		request.setCharacterEncoding("gb2312");
		String opflag = request.getParameter("opflag");
		if("init".equals(opflag))
		{
			//进入页面,列表显示所有的级别
			showlist(request,response);
		}
		else if("del".equals(opflag))
		{
			//删除级别
			delob(request,response);
		}
		else if("add".equals(opflag))
		{
			//添加
			addob(request,response);
		}
		else if("edit".equals(opflag))
		{
			//编辑
			editob(request,response);
		}
		else if("ajax".equals(opflag))
		{
			levelname(request,response);
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}
	
	private void levelname(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		String rspResult = "0";
		
		String levelname = request.getParameter("levelname");
		LevelInfoDAO leveldao = new LevelInfoDAO();
		
		if(levelname != null && !levelname.equals("") )
		{
			String cond = " and li_name='" + levelname + "'";
			List levellist = new ArrayList();
			levellist = leveldao.queryByCondition(cond);
			if(levellist != null && levellist.size() != 0)
			{
				rspResult = "1";
			}
		}
		
		try {
			PrintWriter out = response.getWriter();
			out.write(rspResult);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private void showlist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		List levelinfolist = new ArrayList();
		LevelInfoDAO levelinfodao = new LevelInfoDAO();
		levelinfolist = levelinfodao.queryByCondition(" and li_state='可用'");
		request.setAttribute("levelinfolist", levelinfolist);
		request.getRequestDispatcher("sys_manage\\sys_levelmaintain_delete.jsp").forward(request, response);
	}
	
	private void delob(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
		String levelinfo[] = request.getParameterValues("checkbox");
		LevelInfoDAO levelinfodao = new LevelInfoDAO();
		int j = 0;
		for(int i = 0; i < levelinfo.length; i++)
		{
			LevelInfoVO levelvo = new LevelInfoVO();
			levelvo = (LevelInfoVO)levelinfodao.readObject(" and li_id="+levelinfo[i]);
			levelvo.setLiState("不可用");
			j = levelinfodao.updateObject(levelvo);
		}

		if(j != 0)
			request.getRequestDispatcher("SM_LevelInfoServlet?opflag=init").forward(request, response);
		else
			request.getRequestDispatcher("erropage.jsp").forward(request, response);
	}
	
	private void addob(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		LevelInfoDAO levelinfodao = new LevelInfoDAO();
		LevelInfoVO levelinfovo = new LevelInfoVO();
		
		levelinfovo.setLiName(request.getParameter("levelname"));
		levelinfovo.setLiTag(request.getParameter("tag"));
		String state = request.getParameter("state");
		if("1".equals(state))
			levelinfovo.setLiState("可用");
		else
			levelinfovo.setLiState("不可用");
		
		int i = 0;
		i = levelinfodao.addObject(levelinfovo);
		if(i !=0 )
			request.getRequestDispatcher("SM_LevelInfoServlet?opflag=init").forward(request, response);
		else
			request.getRequestDispatcher("erropage.jsp").forward(request, response);
	}
	
	private void editob(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		LevelInfoDAO levelinfodao = new LevelInfoDAO();
		LevelInfoVO levelinfovo = new LevelInfoVO();
		
		levelinfovo.setLiId(Long.parseLong(request.getParameter("liid")));
		levelinfovo.setLiName(request.getParameter("levelname"));
		levelinfovo.setLiTag(request.getParameter("tag"));
		String state = request.getParameter("state");
		if("1".equals(state))
			levelinfovo.setLiState("可用");
		else
			levelinfovo.setLiState("不可用");
		
		int i = 0;
		i = levelinfodao.updateObject(levelinfovo);
		if(i != 0)
			request.getRequestDispatcher("SM_LevelInfoServlet?opflag=init").forward(request, response);
		else
			request.getRequestDispatcher("erropage.jsp").forward(request, response);
	}
}














⌨️ 快捷键说明

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