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

📄 hotelservlet.java

📁 本软件系统可以实现预定酒店的多方位查询、预订酒店的功能。可以方便人们入住酒店,增加酒店的收入
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        if(action.equals("delHotel")){//------------------------------------------------------------------------delHotel
        	System.out.println ("this is delHotel");
        	String hotelid = request.getParameter("hotelid");
        	try {
        		HotelRemoteHome hotelRemoteHome = lookupHotelRemoteHome();//////////////////////////////////////////////
        		HotelRemote hotelRemote = hotelRemoteHome.findByPrimaryKey(new Integer(hotelid));
        		hotelRemote.remove();
        		HouseTypeRemoteHome houseTypeRemoteHome = lookupHouseTypeRemoteHome();
        		Collection collection = houseTypeRemoteHome.findByHotelId(new Integer(hotelid));
        		Iterator it = collection.iterator();
        		while(it.hasNext()){
        			Object o = it.next();
        			HouseTypeRemote houseTypeRemote = (HouseTypeRemote)PortableRemoteObject.narrow(o,HouseTypeRemote.class);
        			houseTypeRemote.remove();	
        		}
        		forward(request,response,"/HotelServlet?action=HotelManagement");
		    }
		    catch (Exception ex) {
		    	System.out.println ("some error in delect Hotel");
		    }
        	System.out.println ("I will delete the Hotel"+hotelid);
        	
        }
        if(action.equals("HotelManagement")){//-------------------------------------------------------------HotelManagement
     		
			System.out.println ("this is HotelManagement");
        	try {
        		HotelRemoteHome hotelRemoteHome = lookupHotelRemoteHome();//////////////////////////////////////////////
        		Collection collection = hotelRemoteHome.findAll();
        		request.setAttribute("hotelManagement",collection);
        		forward(request,response,"/jsp/hotel/HotelManagement.jsp");
		    }
		    catch (Exception ex) {
		    	out.println("Sorry I can not goto HotelManagement.jsp");
		    }	
        }
        if(action.equals("showHotelContent")){//---------------------------------------------------------------showHotelContent
        	System.out.println ("this is showHotelContent");
        	String hotelid = request.getParameter("hotelid");
        	System.out.println (hotelid);
        	
        	try {
        		HotelRemoteHome hotelRemoteHome = lookupHotelRemoteHome();//////////////////////////////////////////////
        		HotelRemote hotelRemote = hotelRemoteHome.findByPrimaryKey(new Integer(hotelid));
        		request.setAttribute("session_hotelContent",hotelRemote);
        		forward(request,response,"/jsp/hotel/UpdateHotelInfo.jsp");
		    }
		    catch (Exception ex) {
		    	out.println("Sorry I can not goto HotelManagement.jsp");
		    	
		    }
		    
        }
        if(action.equals("updateHotelInfo")){//--------------------------------------------------------------updateHotelContent
        	System.out.println ("this is updateHotelInfo");
        	System.out.println ("-------------------------in updateHotelContent begin----------------------------");
        	
        	
        	String hotelid = request.getParameter("hotelid");
        	Integer hotelPK = Integer.decode(hotelid);
        	String name = request.getParameter("name");
        	
        	String hotelDesc = request.getParameter("hotelDesc");
        	String pic = request.getParameter("pic");
        	String hotelLevel = request.getParameter("hotelLevel");
        	String city = request.getParameter("city");
        	String address = request.getParameter("address");
        	String traffic = request.getParameter("traffic");
        	String fw = request.getParameter("fw");
        	String hy = request.getParameter("hy");
        	String cy = request.getParameter("cy");
        	String xx = request.getParameter("xx");
        	String cCard = request.getParameter("cCard");
        	
        	try {
        		HotelRemoteHome hotelRemoteHome = lookupHotelRemoteHome();
        		HotelRemote hotelRemote = hotelRemoteHome.findByPrimaryKey(hotelPK);
        		hotelRemote.setName(name);
        		hotelRemote.setHotelDesc(hotelDesc);
        		hotelRemote.setPic(pic);
        		hotelRemote.setHotelLevel(hotelLevel);
        		hotelRemote.setCity(city);
        		hotelRemote.setAddress(address);
        		hotelRemote.setTraffic(traffic);
        		hotelRemote.setFw(fw);
        		hotelRemote.setHy(hy);
        		hotelRemote.setCy(cy);
        		hotelRemote.setXx(xx);
        		hotelRemote.setCcard(cCard);
        		//将主键插入Attribute跳转到 UpdateHouseType.jsp页面
        		session.setAttribute("session_hotelPK",hotelPK);
        		HouseTypeRemoteHome houseTypeRemoteHome = lookupHouseTypeRemoteHome();
				Collection collection = houseTypeRemoteHome.findByHotelId(hotelPK);
				Iterator it = collection.iterator();
				request.setAttribute("session_it",it);//将it插入session用于在jsp页面中显示此酒店已经添加的房间类型相信资料
				System.out.println ("go to UpdateHouseType.jsp");
				
				forward(request,response,"/jsp/hotel/UpdateHouseType.jsp");//UpdateHouseType.jsp 同AddHouseType.jsp类型,但功能更强大
		    }
		    catch (Exception ex) {
		    	ex.printStackTrace();
		    }
        	/*
        	System.out.println (hotelid);
        	System.out.println (name);
        	
        	System.out.println (hotelDesc);
        	System.out.println (pic);
        	System.out.println (hotelLevel);
        	System.out.println (city);
        	System.out.println (address);
        	System.out.println (traffic);
        	System.out.println (fw);
        	System.out.println (hy);
        	System.out.println (cy);
        	System.out.println (xx);
        	System.out.println (cCard);	
        	*/
        	System.out.println ("-------------------------in updateHotelContent end-----------------------------");
        	
        }
        if(action.equals("updateHotelTypeInfo")){//------------------------------------------------------ updateHotelTypeInfo
        	System.out.println ("this is updateHotelTypeInfo");	
        }

    }
    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
  
    //Clean up resources
    public void destroy() {
    }
    private HotelRemoteHome lookupHotelRemoteHome() {
    // Lookup the beans home using JNDI

		HotelRemoteHome myHome = null;

		try {

			Hashtable ht = new Hashtable();
		    ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
			ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
			Context ctx = new InitialContext(ht);
			Object home = ctx.lookup("HotelJndiName");

			myHome = (HotelRemoteHome) PortableRemoteObject.narrow(home, HotelRemoteHome.class);

        } catch (Exception e)
        {
            System.out.println("The client was unable to lookup the HotelRemoteHome.");
        }

        return myHome;
	}
	private HouseTypeRemoteHome lookupHouseTypeRemoteHome() {
    // Lookup the beans home using JNDI

		HouseTypeRemoteHome myHome = null;

		try {

			Hashtable ht = new Hashtable();
		    ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
			ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
			Context ctx = new InitialContext(ht);
			Object home = ctx.lookup("HouseTypeJndiName");

			myHome = (HouseTypeRemoteHome) PortableRemoteObject.narrow(home, HouseTypeRemoteHome.class);

        } catch (Exception e)
        {
            System.out.println("The client was unable to lookup the HouseTypeRemoteHome.");
        }

        return myHome;
	}
	
	protected void forward(HttpServletRequest request,HttpServletResponse response,String url)    throws ServletException,IOException {
	    RequestDispatcher dispatcher = request.getRequestDispatcher(url);
	    dispatcher.forward(request, response);
   	}
}

⌨️ 快捷键说明

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