telnumchaxun5servlet.java

来自「这是一个jsp联合javabean的电话查询系统。」· Java 代码 · 共 144 行

JAVA
144
字号
/*
 * Created on 2006-7-14
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.jzgs.telnumber.ec.servlet;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.jzgs.telnumber.ec.Util.DepartmentHandler;
import org.jzgs.telnumber.ec.Util.MyException;
import org.jzgs.telnumber.ec.Util.TelNumValueMap;
import org.jzgs.telnumber.ec.bean.TelNumChaXun5Bean;




/**
 * @author zhangzhen
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TelNumChaXun5Servlet extends HttpServlet {
    
	 protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        
        doPost(request,response);
    }
	 
	/* (non-Javadoc)
	 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	protected void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    HttpSession session = req.getSession(false);
   
    res.setContentType("text/html;charset=GB2312");
    res.setCharacterEncoding("gb2312");


try {
    doExcute(req, res);
} catch (Exception e) {
  
    res.sendRedirect("/JZGSMIS/error/errorpage.jsp");
}
}

/**
* @param request
* @param response
 * @throws MyException
 * @throws IOException
*/
private void doExcute(HttpServletRequest request,
    HttpServletResponse response) throws MyException, IOException {
String forwordJsp = "/TelSearch/处工作人员电话.jsp";

HashMap keyMap = new HashMap();
TelNumValueMap resultMap = new TelNumValueMap();
HttpSession session = request.getSession(false);
ServletContext context = session.getServletContext();
String operateFlag = request.getParameter("operateFlg");
String departmentListHtml=""; 
String personListHtml="";

String departList = null;

String personList = null;

TelNumChaXun5Bean TelBean= new TelNumChaXun5Bean();

String departId="";
String personId="";
try {
    if (operateFlag != null
			&& operateFlag.equals("DEPARTCHANGE")) {
     	session.removeAttribute("DEPAERMENT_SELECT");
     	session.removeAttribute("PERSON_LIST");
     	
     	departId=request.getParameter("department");
     	 departmentListHtml=DepartmentHandler.FUN_GET_LIST_TAG(departId,"department","100","5","changeDepartment");
        personListHtml=DepartmentHandler.FUN_GET_PERSON_LIST_TAG("person","100",departId,"table5","");
		request.setAttribute("DEPAERMENT_SELECT",departmentListHtml);
		request.setAttribute("PERSON_LIST",personListHtml);

	} else if (operateFlag != null
			&& operateFlag.equals("SELECT")) {	
	   String person=request.getParameter("person");
	   resultMap=(TelNumValueMap)TelBean.getResultBean(person);
	   
	   departId=request.getParameter("department");
	   personId=request.getParameter("person");
	   System.out.println(departId+personId);
       departmentListHtml=DepartmentHandler.FUN_GET_LIST_TAG(departId,"department","100","5","changeDepartment");
       personListHtml=DepartmentHandler.FUN_GET_PERSON_LIST_TAG(personId,"person","100",departId,"table5","");
      //	 set new resultList
	   request.setAttribute("resultMap", resultMap);	
	   request.setAttribute("DEPAERMENT_SELECT",departmentListHtml);
	   request.setAttribute("PERSON_LIST",personListHtml);   
		}else{
                                                
		    departmentListHtml=DepartmentHandler.FUN_GET_LIST_TAG("1","department","100","5","changeDepartment");
	        personListHtml=DepartmentHandler.FUN_GET_PERSON_LIST_TAG("person","100","1","table5","");
	        request.setAttribute("DEPAERMENT_SELECT",departmentListHtml);
			request.setAttribute("PERSON_LIST",personListHtml);   
	}

	
//return to forwordJsp
RequestDispatcher dispatcher = getServletContext()
        .getRequestDispatcher(forwordJsp);
dispatcher.forward(request, response);
    
} catch (Exception e) {
   
	e.printStackTrace();
    response.sendRedirect("/JZGSMIS/error/errorPage.jsp");

} finally {
    if (TelBean != null) {
        try {
            TelBean.closeDBConnection();
        } catch (Exception e1) {
            e1.printStackTrace();
            response.sendRedirect("/JZGSMIS/error/errorPage.jsp");
        }
    }
}
}
}

⌨️ 快捷键说明

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