Apache HTTP Componentsライブラリでこれを行うことができます。以下は、HTTPコンポーネントのライブラリで動作するはずのような何か:
<%@ page import="org.apache.http.*, org.apache.http.impl.*, org.apache.http.params.*, org.apache.http.protocol.*, org.apache.http.message.BasicHttpRequest, org.apache.http.util.EntityUtils, java.net.Socket" %>
<%
HttpParams params = new SyncBasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
HttpProtocolParams.setUseExpectContinue(params, true);
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
new RequestContent(),
new RequestTargetHost(),
new RequestConnControl(),
new RequestUserAgent(),
new RequestExpectContinue()});
HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
HttpContext context = new BasicHttpContext(null);
HttpHost host = new HttpHost("www.example.com", 80);
DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
ConnectionReuseStrategy connStrategy = new DefaultConnectionReuseStrategy();
context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
try
{
Socket socket = new Socket(host.getHostName(), host.getPort());
conn.bind(socket, params);
BasicHttpRequest request = new BasicHttpRequest("GET", "/");
request.setParams(params);
httpexecutor.preProcess(request, httpproc, context);
HttpResponse response = httpexecutor.execute(request, conn, context);
response.setParams(params);
httpexecutor.postProcess(response, httpproc, context);
%>
<%=EntityUtils.toString(response.getEntity())%>
<%
}
finally
{
conn.close();
}
%>
コードの記述は、なぜあなたはBeanを作成しないと、そこにそれを使用し、何の良いアイデアではありませんか?コードは同じで、ユーザビリティとテスト容易性ははるかに優れています。 – maaartinus