我在做【文件搜】网站用到的:
高速版(JAVA+Lucene) http://wjsou.com:8080/
低速版(PHP+Mysql) http://wjsou.com
高速版:耗时 0.015s ,找到约 1000 个结果。
千万份数据全部存到内存里面。
模糊匹配搜索,输错了一两个字也没事。
lucene全文检索引擎,无需数据库。
java最简单的方式实现http get请求
需要导入3个包commons-logging-1.2.jar httpclient-4.5.3.jar httpcore-4.4.6.jar,在这里下载http://hc.apache.org/downloads.cgi
package com.xhrrj.lucene.test;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
public class HttpClientTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
String url = "http://suggestion.baidu.com/su?wd=a&action=opensearch";
try {
HttpResponse response = HttpClients.createDefault().execute(
new HttpGet(url));
if (response.getStatusLine().getStatusCode() == 200) {
System.out.println(EntityUtils.toString(response.getEntity()));
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java gbk转utf8
这是我从百度请求边输入边请求,百度返回的是GBK,我网站是utf-8
<%@page import ="org.apache.http.HttpResponse"%>
<%@page import ="org.apache.http.client.methods.HttpGet"%>
<%@page import ="org.apache.http.impl.client.HttpClients"%>
<%@page import ="org.apache.http.util.EntityUtils"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%
String wd=new String(request.getParameter("term").getBytes("ISO-8859-1"),"utf-8");
String url = "http://suggestion.baidu.com/su?wd=" + wd + "&action=opensearch";
try {
HttpResponse response2 = HttpClients.createDefault().execute(new HttpGet(url));
if (response2.getStatusLine().getStatusCode() == 200) {
String result=EntityUtils.toString(response2.getEntity(),"utf-8");
//System.out.println(result);
result=result.substring(wd.length()+4,result.length()-1);
System.out.println(result);
out.println(result);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
%>
javaweb发布到服务器
1.所有用到的lib文件即jar文件全部放到apache-tomcat下的lib文件夹里。自己写的java类也export导出为jar放在里面。
2.把html 和jsp放到根目录
3.设置apache-tomcat-7.0.72-windows-x86\apache-tomcat-7.0.72\conf\server.xml
端口:80
网站根目录:比如C:\WWW
绑定域名:www.wjsou.com
说明:网上说导出war文件,我导了,为什么不行,坑。只好把自己写的java类也export导出为jar放在里面。