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

📄 googleservlet.java

📁 一个基于PlaceLab的室内和室外的智能导航系统
💻 JAVA
字号:
package org.placelab.demo.webservices;import java.util.Hashtable;import org.placelab.core.TwoDCoordinate;import org.placelab.proxy.HTTPRequest;import org.placelab.proxy.HTTPResponse;import org.placelab.proxy.ServletServer;public class GoogleServlet extends WebServlet {    public GoogleServlet(WebService webService) {        super(webService, "/google", "local.google.com");    }	    // print the last estimate we got from the tracker    public HTTPResponse serviceRequest(HTTPRequest req) {        String url = req.url.getPath();        if (url.indexOf("/google/query")==0) {            return serviceQueryRequest(req);        } else {            return serviceFormRequest(req);        }    }    private HTTPResponse serviceFormRequest(HTTPRequest req) {        return createResponse("Location-based search (local.google.com)",                              "http://www.placelab.org/services/google-form.php?url=" + ServletServer.getProperURL() + "/google/query");    }    private HTTPResponse serviceQueryRequest(HTTPRequest req) {        TwoDCoordinate position = getEstimatedPosition();        String queryUrl = req.url.getQuery();        int index = (queryUrl != null ? queryUrl.indexOf("query=") : -1);        if (index < 0) {            return serviceFormRequest(req);        }        index += 6; // skip over the "query=" part        int end = queryUrl.indexOf("&", index);        if (end < index) end = queryUrl.length();        String query = queryUrl.substring(index, end);        String url = "http://local.google.com/local?sc=1&q="+query+"&near="+            position.getLatitude() + "%2C" + position.getLongitude() +             "&btnG=Google+Search";        return createResponse("Google Search: " + query + " near you (powered by Place Lab)", url);    }        // servlets can add headers to outgoing http requests.    public Hashtable injectHeaders(HTTPRequest req) {        return null;    }}

⌨️ 快捷键说明

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