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

📄 rentservlet.java

📁 提供房屋出租信息
💻 JAVA
字号:
package cwnu.com.servlets;

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

import cwnu.com.dataiud.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;
import cwnu.com.rentInfo.*;

import cwnu.com.saleInfo.*;

public class rentServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public rentServlet() {
		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 {
		/*
		 * 得到页面信息
		 */
		String action = request.getParameter("action");

		

		idudata iduinfo = new idudata();
		if (action.equals("delete")) 
		{
			String type = request.getParameter("type");
			String id = request.getParameter("infoid");
			String power = request.getParameter("power");
			if (type.equals("rent")) 
			{
				if (iduinfo.iduInfo("delete from RentOutAndIn where ID='" + id
						+ "'")) {
					JOptionPane.showMessageDialog(null, "删除成功");
					ArrayList<rentInfoVo> list = (ArrayList<rentInfoVo>) request
							.getSession().getAttribute("rentList");
					for (int i = 0; i < list.size(); i++)
						if (list.get(i).getID().equals(id)) {
							list.remove(i);
							break;
						}

					request.getSession().setAttribute("rentList", list);
					         if(power.equals("user"))
							{
					            response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
							}else
							{
								response.sendRedirect("Jsp/administrater/admin.jsp");
							}

				}

			}else
			{
				if (iduinfo.iduInfo("delete from SaleAndBuy where ID='" + id
						+ "'")) {
					JOptionPane.showMessageDialog(null, "删除成功");
					ArrayList<saleInfoVo> list = (ArrayList<saleInfoVo>) request
							.getSession().getAttribute("saleList");
					for (int i = 0; i < list.size(); i++)
						if (list.get(i).getID().equals(id)) {
							list.remove(i);
							break;
						}

					request.getSession().setAttribute("saleList", list);
					response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");

				}
			}
		} else
		{		
			String region = new String(request.getParameter("region").getBytes("ISO-8859-1"), "GBK");
	        String area = new String(request.getParameter("area").getBytes("ISO-8859-1"), "GBK");
	        String floor = request.getParameter("floor");

	        String water = "";
	        String power = "";
	        String gas = "";
	        String net = "";
	                try {
		                     water = new String(request.getParameter("water").getBytes("ISO-8859-1"), "GBK");
		                     power = new String(request.getParameter("power").getBytes("ISO-8859-1"), "GBK");
		                     gas = new String(request.getParameter("gas").getBytes("ISO-8859-1"), "GBK");		
		                     net = new String(request.getParameter("net").getBytes("ISO-8859-1"), "GBK");
	                   } catch (Exception e) {

	                     }
	        String contacts = new String(request.getParameter("contacts").getBytes("ISO-8859-1"), "GBK");
	        String contactMethod = request.getParameter("contactMethod");
	        String registrationDate = new String(request.getParameter("registrationDate").getBytes("ISO-8859-1"), "GBK");
	        String houseType = new String(request.getParameter("houseType").getBytes("ISO-8859-1"), "GBK");
	        String remark = new String(request.getParameter("remark").getBytes("ISO-8859-1"), "GBK");
	        String userid = (String) request.getSession().getAttribute("userid");
	
	        String bedRoom = request.getParameter("bedRoom");
	        String livingRoom = request.getParameter("livingRoom");
	        String toilet = request.getParameter("toilet");

	        String infraction = water + "  " + power + "  " + gas + "  " + net;
               System.out.println(water+power+gas+net);
	        if (infraction.length() == 6)
		            infraction = "无";	
	        
	        if(action.equals("update"))
	        {
	        	
	        }
	        if(action.equals("insert"))
	        {   String price = request.getParameter("price");
	        	String effectiveTime = new String(request.getParameter("effectiveTime").getBytes("ISO-8859-1"),"GBK");
	        	
	        	String rightsDiscript = new String(request.getParameter("rightsDiscript").getBytes("ISO-8859-1"),"GBK");
	        	
	        	System.out.println(rightsDiscript);
	        	String houseAddress = "";
	        	String useType = "";
	        	String saleType= "";
	        	String type= request.getParameter("type");
	        	if(type.equals("civilsale"))
	        	{
	        		useType = "民用";
	        		saleType = "出售";
	        		houseAddress =new String(request.getParameter("houseAddress").getBytes("ISO-8859-1"),"GBK");
	        	}else if(type.equals("civilin"))
	        	{
	        		useType="民用";
	        		saleType = "买进";
	        	}else if(type.equals("bussinesssale"))
	        	{
	        		useType = "商用";
	        		saleType = "出售";
	        		houseAddress =new String(request.getParameter("houseAddress").getBytes("ISO-8859-1"),"GBK");
	        	}else if(type.equals("bussinessin"))
	        	{
	        		useType = "商用";
	        		saleType = "买进";
	        	}
	        	setSInfoList objsetlist = new setSInfoList();
	        	if(request.getParameter("selectsql").equals("update"))
	        	{
	        		String upid = request.getParameter("upid");
		        	String sqlupdate="update SaleAndBuy set region='"+region+"',houseAddress='"+houseAddress+"',rightsDiscript='"+rightsDiscript+"',area='"+area+"',bedRoom='"+bedRoom+"',livingRoom='"+livingRoom+"',toilet='"+toilet+"',floor='"+floor+"',price='"+price+"',infrastruction='"+infraction+"',contacts='"+contacts+"',contactMethod='"+contactMethod+"',registrationDate='"+registrationDate+"',effectiveTime='"+effectiveTime+"',remark='"+remark+"' where ID='"+upid+"'";
		        	
		        	if(iduinfo.iduInfo(sqlupdate))
		        	{
			        	ArrayList<saleInfoVo> list = objsetlist.setList("select * from SaleAndBuy");
						request.getSession().setAttribute("saleList", list);
						JOptionPane.showMessageDialog(null, "修改成功");
						response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
		        	}else
		        	{
						JOptionPane.showMessageDialog(null, "修改失败");
						response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
		        	}
		        	
		        	
		        	
	        	}else
	        	{
				String sqlinsert="insert into SaleAndBuy(userID,houseType,useType,outOrIn,region,houseAddress,rightsDiscript,area,bedRoom,livingRoom,toilet,floor,price,infrastruction,contacts,contactMethod,registrationDate,effectiveTime,remark) values('"
					+ Integer.parseInt(userid)+ "','"+houseType+ "','"+ useType+ "','"+ saleType+ "','"+ region+ "','"+ houseAddress+ "','"+rightsDiscript+"','"+ area+ "','"+ bedRoom+ "','"+ livingRoom+ "','"+ toilet+ "','"+ floor+ "','"+ price+ "','"+ infraction+ "','"+ contacts+ "','"+ contactMethod+ "','"+ registrationDate +"','"+effectiveTime+"','"+remark+"')";	
	        	
                System.out.println(rightsDiscript);
				if(iduinfo.iduInfo(sqlinsert))
				{
		        	ArrayList<saleInfoVo> list = objsetlist.setList("select * from SaleAndBuy");
					request.getSession().setAttribute("saleList", list);
					JOptionPane.showMessageDialog(null, "添加成功");
					response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
				}else
				{
					JOptionPane.showMessageDialog(null, "添加失败");
					response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
				}
	        	}
	        	
	        		        	
	        }
	        
	        

			if (action.equals("civilrentin") || action.equals("updaterentin"))// 民用房求租信息插入和更新
			{
		        String rentPrice = request.getParameter("rentPrice");
				String rentPersons = request.getParameter("rentPersons");
				String sql = null;				
				if (action.equals("civilrentin")) {
					
					if(request.getParameter("Ctype").equals("rentin"))
					{
						sql="insert into RentOutAndIn(userID,rentPersons,houseType,useType,outOrIn,region,houseAddress,area,bedRoom,livingRoom,toilet,floor,rentPrice,infrastruction,contacts,contactMethod,remark,registrationDate) values('"
							+ userid+ "','"+ rentPersons+ "','"+ houseType+ "','"+ "民用"+ "','"+ "求租"+ "','"+ region+ "','"+ ""+ "','"+ area+ "','"+ bedRoom+ "','"+ livingRoom+ "','"+ toilet+ "','"+ floor+ "','"+ rentPrice+ "','"+ infraction+ "','"+ contacts+ "','"+ contactMethod+ "','"+ remark+ "','"+ registrationDate + "')";
					}
					else
					{
						 String houseAddress = new String(request.getParameter("houseAddress").getBytes("ISO-8859-1"), "GBK");					 
						 sql = "insert into RentOutAndIn(userID,rentPersons,houseType,useType,outOrIn,region,houseAddress,area,bedRoom,livingRoom,toilet,floor,rentPrice,infrastruction,contacts,contactMethod,remark,registrationDate) values('"
							+ userid+ "','"+"0"+ "','"+ houseType+ "','"+ "民用"+ "','"+ "出租"+ "','"+ region+ "','"+ houseAddress+ "','"+ area+ "','"+ bedRoom+ "','"+ livingRoom+ "','"+ toilet+ "','"+ floor+ "','"+ rentPrice+ "','"+ infraction+ "','"+ contacts+ "','"+ contactMethod+ "','"+ remark+ "','"+ registrationDate + "')";
					}
					
					if (iduinfo.iduInfo(sql)) {
						JOptionPane.showMessageDialog(null, "添加成功");
						setRInfoList list = new setRInfoList();
						ArrayList<rentInfoVo> rinfovolist = list
								.setList("select * from RentOutAndIn");
						request.getSession().setAttribute("rentList",
								rinfovolist);
						response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
					} else {
						JOptionPane.showMessageDialog(null, " 添加失败");
						response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
					}
				} else if (action.equals("updaterentin"))// 求租信息更新
				{
					String sqlstr=null;

					StringBuffer sqlupdate = new StringBuffer();
					

					
					
					if(request.getParameter("utype").equals("updatein"))
					{
						sqlupdate.append("update RentOutAndIn set rentPersons='");
						sqlupdate.append(rentPersons + "',houseType='");
						sqlupdate.append(houseType + "',region='");
						sqlupdate.append(region + "',houseAddress='");
						sqlupdate.append("" + "',area='");
						sqlupdate.append(area + "',bedRoom='");
						sqlupdate.append(bedRoom+"',livingRoom='");
						sqlupdate.append(livingRoom + "',toilet='");
						sqlupdate.append(toilet+"',floor='");
						sqlupdate.append(floor + "',rentPrice='");
						sqlupdate.append(rentPrice + "',infrastruction='");
						sqlupdate.append(infraction + "',contacts='");
						sqlupdate.append(contacts + "',contactMethod='");
						sqlupdate.append(contactMethod + "',remark='");
						sqlupdate.append(remark + "',registrationDate='");
						sqlupdate.append(registrationDate + "' where ID='");
						sqlupdate.append(request.getParameter("infoid") + "'");
						
						sqlstr= sqlupdate.toString();
					}else if(request.getParameter("utype").equals("updateout"))
					{
						
						String houseAddress = new String(request.getParameter("houseAddress").getBytes("ISO-8859-1"), "GBK");					 
						sqlupdate.append("update RentOutAndIn set rentPersons='");
						sqlupdate.append(rentPersons + "',houseType='");
						sqlupdate.append(houseType + "',region='");
						sqlupdate.append(region + "',houseAddress='");
						sqlupdate.append(houseAddress + "',area='");
						sqlupdate.append(area + "',bedRoom='");
						sqlupdate.append(bedRoom+"',livingRoom='");
						sqlupdate.append(livingRoom + "',toilet='");
						sqlupdate.append(toilet+"',floor='");
						sqlupdate.append(floor + "',rentPrice='");
						sqlupdate.append(rentPrice + "',infrastruction='");
						sqlupdate.append(infraction + "',contacts='");
						sqlupdate.append(contacts + "',contactMethod='");
						sqlupdate.append(contactMethod + "',remark='");
						sqlupdate.append(remark + "',registrationDate='");
						sqlupdate.append(registrationDate + "' where ID='");
						sqlupdate.append(request.getParameter("infoid") + "'");					
						sqlstr= sqlupdate.toString();
					}

					if (iduinfo.iduInfo(sqlstr)) {
						JOptionPane.showMessageDialog(null, "更新成功");
						setRInfoList list = new setRInfoList();
						ArrayList<rentInfoVo> rinfovolist = list.setList("select * from RentOutAndIn");
						request.getSession().setAttribute("rentList",rinfovolist);
						response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
					} else {
						JOptionPane.showMessageDialog(null, "更新失败");
						response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
					}
				}
			}
		}

	}

	/**
	 * 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -