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

📄 advancedsearchservlet.java

📁 This is a project used to find a corresondin location from place
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package com.gecb.mcompanion.web.server;import com.gecb.mcompanion.web.db.AdvancedSearchManager;import java.io.*;import java.net.*;import javax.servlet.*;import javax.servlet.http.*;/** * * @author Administrator */public class AdvancedSearchServlet extends HttpServlet {    /**     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.    * @param request servlet request    * @param response servlet response    */    HttpSession savepreference ;    protected void processRequest(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException     {         PrintWriter out=null;         String advance ="";       try{        response.setContentType("text/html;charset=UTF-8");        out= response.getWriter();        String cordinates = request.getParameter("cordinates");        String str = request.getParameter("input");     System.out.println("Message Frm Client :"+str);        String[] params = str.split("#");        for(int k=0;k<params.length;k++)        {            System.out.println(params[k]);        }       AdvancedSearchManager AdSeMa;       AdSeMa = new AdvancedSearchManager();                 //    copied from test  for(int i= 0 ; i< params.length ; i++)    {     System.out.println(params[i]);      AdSeMa = new AdvancedSearchManager();          String substr = params[i];     String paramSub[] = params[i].split(":");     System.out.println(paramSub[0]);     String criteriastring[]=paramSub[1].split("@");         if(paramSub[0].equals("hospital"))     {         String resultfield[]={"hospital_name","hospital_type","hospital_speciality"};         //String field[] ={"hospital_type","hospital_speciality"};        //          String query1=search(criteriastring, paramSub,resultfield,cordinates);                 System.out.println(query1);         advance += AdSeMa.SearchResources(query1,"hospital");        // System.out.println("RESULTS");     }     else if(paramSub[0].equals("resturant"))       {      String resultfield[]={"resturant_name","resturant_type","resturant_menu"};                     //String field[] ={"resturant_type","resturant_menu"};                     String query1=search(criteriastring, paramSub,resultfield,cordinates);                                         System.out.println(query1);                                         advance+=AdSeMa.SearchResources(query1,"resturant");                   // AdSeMa.SearchResources(query1,"resturant");                           }     else if(paramSub[0].equals("institution"))          {                     String resultfield[]={"name","courses","facilities"};                    // String field[] ={"courses","facilities"};                      String query1=search(criteriastring, paramSub,resultfield,cordinates);                      System.out.println(query1);                       advance +=AdSeMa.SearchResources(query1,"institution");                               }     else if(paramSub[0].equals("religiousspots"))          {                                           String resultfield[]={"rs_name","mythology","history"};                    // String field[] ={"mythology","history"};                     String query1=search(criteriastring, paramSub,resultfield,cordinates);System.out.println(query1);                     advance +=AdSeMa.SearchResources(query1,"religiousspots");          }    else if(paramSub[0].equals("petrolpump"))          {                                           String resultfield[]={"petrolpump_name","petrolpump-type","petrolpump_speciality"};                     //String field[] ={"petrolpump_type","petrolpump_speciality"};                      String query1=search(criteriastring, paramSub,resultfield,cordinates);                     System.out.println(query1);                     advance +=AdSeMa.SearchResources(query1,"petrolpump");          }    else if(paramSub[0].equals("shop"))          {                                           String resultfield[]={"shop_name","shop_type","facilities"};                     //String field[] ={"shop_type","facilities"};                     String query1=search(criteriastring, paramSub,resultfield,cordinates);                     System.out.println(query1);                     advance +=AdSeMa.SearchResources(query1,"shop");          }    else if(paramSub[0].equals("airport"))          {                                           String resultfield[]={"airport_name","airport_type","SPECIALITIES"};                     //String field[] ={"airport_type","SPECIALITIES"};                      String query1=search(criteriastring, paramSub,resultfield,cordinates);                     System.out.println(query1);                     advance +=AdSeMa.SearchResources(query1,"airport");          }    else if(paramSub[0].equals("tourlocation"))          {                                           String resultfield[]={"tourlocation_name","tourlocation_description","tourlocation_speciality"};                     //String field[] ={"tourlocation_description","tourlocation_speciality"};                      String query1=search(criteriastring, paramSub,resultfield,cordinates);                     System.out.println(query1);                     advance +=AdSeMa.SearchResources(query1,"tourlocation");          }     /* else if(paramSub[0].equals("Location"))          {          String resultfield[]={"resturant_name","resturant_type","resturant_menu"};                     String field[] ={"name","speciality"};                     String query1=search(field, paramSub);                     System.out.println(query1);                     advance += AdSeMa.SearchLocation(query1);          }  */        }        }catch(Exception e)        {            e.printStackTrace();        }    out.println(advance); } public String search(String fields[],String paramSub[],String resultfield[],String cordinates) {    String result="";    String sqlquery="";     String cord[] = cordinates.split(":");    float latitude = Float.parseFloat(cord[0]);    float longitude =Float.parseFloat(cord[1]);                 //changed query                System.out.println(sqlquery)    ;    try{        sqlquery= "SELECT ((ACOS(SIN("+ latitude+"* PI() / 180) *SIN(address.latitude * PI() / 180) + COS("+latitude+" * PI() / 180) * COS(address.latitude * PI()/ 180) * COS(("+longitude+"- address.longitude) * PI() / 180)) * 180 / PI()) * 60 *1.1515) AS distance,"+resultfield[0]+","+resultfield[1]+","+resultfield[2]+",city,latitude,longitude from "+paramSub[0]+",address where address.address_id="+paramSub[0]+".address_id ";   // sqlquery="select "+resultfield[0]+","+resultfield[1]+","+resultfield[2]+",city,latitude,longitude from "+paramSub[0]+",address where address.address_id="+paramSub[0]+".address_id";     System.out.println(sqlquery);    int count=0;     /*for(int j=0;j<paramSub.length;j++)     {      if(j==1 && (!paramSub[j].trim().equals("")))       {        sqlquery +=" and "+fields[0]+" like'%"+ paramSub[j].toUpperCase()+"%'";            count++;       }       else if(j==2 &&(!paramSub[j].trim().equals("")))       {          if(count>0)          sqlquery +="and "  ;          sqlquery +=fields[1]+" like'%"+ paramSub[j].toUpperCase()+"%'";        }     } */    for(int j=2,i=0;j<paramSub.length;j++,i++)     {              sqlquery +=" and "+fields[i]+" like'%"+ paramSub[j].toUpperCase()+"%'";                              }     }catch(Exception e)    {        e.printStackTrace();    }     System.out.println("quer="+sqlquery);     return sqlquery; }           // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">    /**     * Handles the HTTP <code>GET</code> method.    * @param request servlet request    * @param response servlet response    */    protected void doGet(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException     {        processRequest(request, response);            }     /**     * Handles the HTTP <code>POST</code> method.    * @param request servlet request    * @param response servlet response    */    protected void doPost(HttpServletRequest request, HttpServletResponse response)    throws ServletException, IOException     {        processRequest(request, response);    }    /**     * Returns a short description of the servlet.    */    public String getServletInfo()    {        return "Short description";    }    // </editor-fold>}

⌨️ 快捷键说明

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