tounitaddcreateadd.java

来自「实现银行系统中某个部门的计算机设备管理、公共信息管理、权限用户管理、系统设置等,」· Java 代码 · 共 109 行

JAVA
109
字号
package com.isoftstone.banktearm1.to;
/*
 * 07作成部门及机构
 */
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

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

import com.isoftstone.banktearm1.dao.UnitDao;
import com.isoftstone.banktearm1.db.DB;

public class ToUnitAddCreateAdd extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public ToUnitAddCreateAdd() {
		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 {

		DB db=new DB();
		UnitDao ud=new UnitDao();
		String url="";
		try{
			String unitname=(String)request.getAttribute("unitname");
			String unitmemo=(String)request.getAttribute("unitmemo");
			Connection con=db.getConnection();
			Statement stmt=con.createStatement();
			String sql="select * from unit";
			ResultSet rs=stmt.executeQuery(sql);
			boolean b=false;
			while(rs.next()){
				String name=rs.getString("UnitName");
				if(name.equals(unitname) || unitname.equals(""))
					b=true;
			}
			if(b)
				url="JspUnitAddCreateError.jsp";
			else{
				request.setAttribute("UnitName", unitname);
				request.setAttribute("Unitmemo", unitmemo);
				int id=ud.getMax("ID")+1;
				int unitid=ud.getMax("UnitId")+1;
				ud.insertUnit(id, unitid, unitname, unitmemo);
				url="JspUnitAddCreate.jsp";
			}
			db.closs(stmt,con);
		}catch(Exception e){
			request.setAttribute("errorMessage",e.getMessage());
			request.getRequestDispatcher("BankTeam1ErrorPage.jsp").forward(request,response);
		}
	    request.getRequestDispatcher(url).forward(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 {

		this.doGet(request, response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

⌨️ 快捷键说明

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