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

📄 commonservlet.java

📁 使用myeclipse进行的项目设计实例
💻 JAVA
字号:
package cn.com.zzrd.easy.bass.common;

import java.io.IOException;
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 javax.servlet.http.HttpSession;

import cn.com.zzrd.easy.bass.toolkits.ReadProperty;

public class CommonServlet extends HttpServlet {

	/**
	 * 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)
	{
		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)
	{
		/*变量定义*/
		HttpSession session = request.getSession(); 
		CommonDAO dao = new CommonDAO();
		int nSampleCode = 0;
		
		try{
			
			//取得SampleCode
			nSampleCode = ReadProperty.getInt("samplecode");
			if(nSampleCode == 1){
				/* 变量声明 */
				List costDivList = new ArrayList();
				List truckClassList = new ArrayList();
				/* 检索字段 */
				costDivList = dao.getCommonList("MJ60P008", "COSTDIV");
				truckClassList = dao.getCommonList("MJ60P008", "TRUCKCLASS");
				/* 检索出来的字段list保存到session中 */
				session.setAttribute("costDivList", costDivList);
				session.setAttribute("truckClassList", truckClassList);
                //画面迁移
				request.getRequestDispatcher("/j60p1210101.jsp").forward(request, response);
			} else if(nSampleCode == 2){
				//变量声明
				List travelDivList = new ArrayList();
				//检索字段
				travelDivList = dao.getCommonList("MJ60P050", "TRAVEL_DIV");
				//检索出来的字段list保存到session中
				session.setAttribute("travelDivList", travelDivList);
				//画面迁移
				request.getRequestDispatcher("/j60p6150101.jsp").forward(request, response);
				
			} else if(nSampleCode == 3){
				/* 变量声明 */
				List sellerList = new ArrayList();
				List nameToList = new ArrayList();
				List ycList = new ArrayList();
				/* 检索字段 */
				sellerList = dao.getCommonList("MJ60Y010", "SELLERCODE");
				nameToList = dao.getCommonList("MJ60Y019", "END_CD");
				ycList = dao.getCommonList("MJ60K001", "YC");
				/* 检索出来的字段list保存到session中 */
				session.setAttribute("sellerList", sellerList);
				session.setAttribute("nameToList", nameToList);
				session.setAttribute("ycList", ycList);
				//画面迁移
				request.getRequestDispatcher("/P3110101").forward(request, response);
				
			} else {
				//抛出错误信息
				throw new RuntimeException("The <i><font color=\"blue\">samplecode</font></i> you set is wrong. \n " +
						"Plz reset it on the \n" +
						"<div align=\"center\"><i><font color=\"blue\">Resource.properties</font></i></div>");
			}
		} catch(Exception e){
			e.printStackTrace();
			/* 设定错误信息&路径 */
			request.setAttribute("errContent", e.getMessage());
			request.setAttribute("errPath", request.getServletPath());
			try{
				//迁移到错误处理页面
				request.getRequestDispatcher("/error.jsp").forward(request, response);
			}catch(Exception e1){
				e1.printStackTrace();
			}
		}
	}

}

⌨️ 快捷键说明

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