public class Main { public static void main(String[] args) throws Exception {
// Create and initialize HTTP parameters
HttpParams params = new BasicHttpParams();
ConnManagerParams.setMaxTotalConnections(params, 100);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(cm, params); // create an array of URIs to perform GETs on
String[] urisToGet = {
"http://www.baidu.com",
"http://www.sohu.com"
}; // create a thread for each URI
GetThread[] threads = new GetThread[urisToGet.length];
try{
for (int i = 0; i < threads.length; i++) {
HttpGet httpget = new HttpGet(urisToGet[i]);
threads[i] = new GetThread(httpClient, httpget, i + 1);
}
// start the threads
for (int j = 0; j < threads.length; j++) {
threads[j].start();
}
// join the threads
for (int j = 0; j < threads.length; j++) {
threads[j].join();
}
}finally {
httpClient.getConnectionManager().shutdown();
}
} /**
* A thread that performs a GET.
*/
public static class GetThread extends Thread { private final HttpClient httpClient;
private final HttpContext context;
private final HttpGet httpget;
private final int id; public GetThread(HttpClient httpClient, HttpGet httpget, int id) {
this.httpClient = httpClient;
this.context = new BasicHttpContext();
this.httpget = httpget;
this.id = id;
} /**
* Executes the GetMethod and prints some status information.
*/
@Override
public void run() { System.out.println(id + " - about to get something from " + httpget.getURI()); try {
HttpResponse response = httpClient.execute(httpget, context);
System.out.println(id + ":" +response.getStatusLine());
} catch (Exception e) {
httpget.abort();
System.out.println(id + " - error: " + e);
}
}
}
}怎么输出到页面上!!谢谢各位了!
// Create and initialize HTTP parameters
HttpParams params = new BasicHttpParams();
ConnManagerParams.setMaxTotalConnections(params, 100);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(cm, params); // create an array of URIs to perform GETs on
String[] urisToGet = {
"http://www.baidu.com",
"http://www.sohu.com"
}; // create a thread for each URI
GetThread[] threads = new GetThread[urisToGet.length];
try{
for (int i = 0; i < threads.length; i++) {
HttpGet httpget = new HttpGet(urisToGet[i]);
threads[i] = new GetThread(httpClient, httpget, i + 1);
}
// start the threads
for (int j = 0; j < threads.length; j++) {
threads[j].start();
}
// join the threads
for (int j = 0; j < threads.length; j++) {
threads[j].join();
}
}finally {
httpClient.getConnectionManager().shutdown();
}
} /**
* A thread that performs a GET.
*/
public static class GetThread extends Thread { private final HttpClient httpClient;
private final HttpContext context;
private final HttpGet httpget;
private final int id; public GetThread(HttpClient httpClient, HttpGet httpget, int id) {
this.httpClient = httpClient;
this.context = new BasicHttpContext();
this.httpget = httpget;
this.id = id;
} /**
* Executes the GetMethod and prints some status information.
*/
@Override
public void run() { System.out.println(id + " - about to get something from " + httpget.getURI()); try {
HttpResponse response = httpClient.execute(httpget, context);
System.out.println(id + ":" +response.getStatusLine());
} catch (Exception e) {
httpget.abort();
System.out.println(id + " - error: " + e);
}
}
}
}怎么输出到页面上!!谢谢各位了!
解决方案 »
- 一个WEB项目的表单注册问题
- 对于运行在tomcat下的java项目进行加密 class文件不可以反编译 有什么新技术可以实现?
- 这个错误是什么意思,
- myeclipse5.5中为什么没有Persistence Core Libraries?
- 在jsp中,用ArrayList在多次刷新页面出现NullPointerExcection的问题,困扰我多日的问题
- XMLHttpRequest提交问题
- 在servlet中有request.setAttribute,在javabean里有没有实现setAttribute的方法?
- 一个java包在一个发布目录下,能否连接多个数据库?我的两部分jsp程序只能显示同一个数据库的内容。
- 为什么我的table展不开?
- 请问哪里可以找到显示农历时间的免费代码?
- Jsp + Oracle 如何取回id,报错getInt not implemented for class oracle.jdbc.driver.T4CRo
- 關於Javascript 控制 TabbedPanels(Spry) 的問題
怎么输出啊,在JSP怎么调用类里面的东西啊,麻烦你了!!
<%@ page import="类的路径" %>
然后在jsp页面里面用小脚本写代码
<%
//例子如userInfo存在作用域中
<%out.print(userInfo.getName)%>
%>