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

📄 searchservlet.java

📁 本软件系统可以实现预定酒店的多方位查询、预订酒店的功能。可以方便人们入住酒店,增加酒店的收入
💻 JAVA
字号:
package com.abc.hotel;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.*;
import javax.rmi.*;
import javax.ejb.*;
import com.abc.hotel.SearchHotelHome;
import com.abc.hotel.SearchHotel;
//import sun.jdbc.rowset.*;


public class SearchServlet extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=GBK";
    
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("gb2312");
        HttpSession session = request.getSession();
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        String action = (String)request.getParameter("action");
        if(action.equals("search")){
        	System.out.println ("this is in SearchServlet");
        	String city = request.getParameter("city");
        	String indate = request.getParameter("indate");
        	String outdate = request.getParameter("outdate");
        	session.setAttribute("indate",indate);
        	session.setAttribute("outdate",outdate);
        	String vip_price = request.getParameter("vip_price");
        	String name = request.getParameter("hotelname");
        	String price_str = null;
		    if(vip_price.equals("0")){
		    	//System.out.println ("vip_price > 0");
		    	price_str = "vip_price > 0";
		    }else if(vip_price.equals("250")){
		    	//System.out.println ("vip_price <= 250");
		    	price_str = "vip_price <= 250";
		    }else if(vip_price.equals("400")){
		    	//System.out.println ("vip_price between 250 and 400");
		    	price_str = "vip_price between 250 and 400";
		    }else if(vip_price.equals("600")){
		    	//System.out.println ("vip_price between 400 and 600");
		    	price_str = "vip_price between 400 and 600";
		    }else if(vip_price.equals("800")){
		    	//System.out.println ("vip_price between 600 and 800");
		    	price_str = "vip_price between 600 and 800";
		    }else if(vip_price.equals("800up")){
		    	//System.out.println ("vip_price >= 800");
		    	price_str = "vip_price >= 800";
		    }
		   	
        	try {
        		
        		SearchHotelHome searchHotelHome = lookupHome();
        	
        		SearchHotel searchHotel = searchHotelHome.create();
        		javax.sql.RowSet result = searchHotel.getMainPageContent(price_str,city,name);
        		request.setAttribute("main_result",result);
		    }
		    catch (CreateException ex) {
		    	ex.printStackTrace();
		    }
		    
		    //javax.sql.RowSet houseTypeResult = searchHotel.getHouseTypeContent(hotelid,price_str);
		    request.setAttribute("session_price_str",price_str);
		    request.setAttribute("session_city",city);
		   
		    forward(request,response,"/jsp/hotel/HotelSearchResult.jsp");
		}
        	
    }
    //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 SearchHotelHome lookupHome() {
    // Lookup the beans home using JNDI

		SearchHotelHome 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("SearchHotelJndiName");

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

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

        return myHome;
	}
    /*
    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 + -