主题:Httpclient 问题...高手请进!
我的源代码如下:
GetSample.java
package test;
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class GetSample{
String id="";
String psw="";
public void id(String id){
id=this.id;
}
public void psw(String psw){
psw=this.psw;
}
public byte[] doit(String url) {
//构造HttpClient的实例
HttpClient httpClient = new HttpClient();
//创建GET方法的实例
GetMethod getMethod = new GetMethod(url);
//使用系统提供的默认的恢复策略
getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler());
try {
//执行getMethod
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: "
+ getMethod.getStatusLine());
}
return getMethod.getResponseBody();
} catch (HttpException e) {
return new byte[123];
} catch (IOException e) {
//发生网络异常
return new byte[456];
} finally {
//释放连接
getMethod.releaseConnection();
}
}
}
dologin.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="GetSample" class="test.GetSample" scope="page">
</jsp:useBean>
<%
byte[] html;
String url="http://www.hpedi.com.cn";
html=GetSample.doit(url);
if(html==null){
out.print("wrong");
}else{
out.println(html);
}
%>
</body>
</html>
在eclipse 上没出错
打开网页出错如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /dologin.jsp:16
13: <%
14: byte[] html;
15: String url="http://www.hpedi.com.cn";
16: html=GetSample.doit(url);
17: if(html==null){
18: out.print("wrong");
19: }else{
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: org/apache/commons/codec/DecoderException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.dologin_jsp._jspService(dologin_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
test.GetSample.doit(GetSample.java:22)
org.apache.jsp.dologin_jsp._jspService(dologin_jsp.java:66)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
请高手指教!!!无限感激!!
[em1][em1]
GetSample.java
package test;
import java.io.IOException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class GetSample{
String id="";
String psw="";
public void id(String id){
id=this.id;
}
public void psw(String psw){
psw=this.psw;
}
public byte[] doit(String url) {
//构造HttpClient的实例
HttpClient httpClient = new HttpClient();
//创建GET方法的实例
GetMethod getMethod = new GetMethod(url);
//使用系统提供的默认的恢复策略
getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler());
try {
//执行getMethod
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode != HttpStatus.SC_OK) {
System.err.println("Method failed: "
+ getMethod.getStatusLine());
}
return getMethod.getResponseBody();
} catch (HttpException e) {
return new byte[123];
} catch (IOException e) {
//发生网络异常
return new byte[456];
} finally {
//释放连接
getMethod.releaseConnection();
}
}
}
dologin.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="GetSample" class="test.GetSample" scope="page">
</jsp:useBean>
<%
byte[] html;
String url="http://www.hpedi.com.cn";
html=GetSample.doit(url);
if(html==null){
out.print("wrong");
}else{
out.println(html);
}
%>
</body>
</html>
在eclipse 上没出错
打开网页出错如下:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /dologin.jsp:16
13: <%
14: byte[] html;
15: String url="http://www.hpedi.com.cn";
16: html=GetSample.doit(url);
17: if(html==null){
18: out.print("wrong");
19: }else{
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:467)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
javax.servlet.ServletException: org/apache/commons/codec/DecoderException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.dologin_jsp._jspService(dologin_jsp.java:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
test.GetSample.doit(GetSample.java:22)
org.apache.jsp.dologin_jsp._jspService(dologin_jsp.java:66)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
请高手指教!!!无限感激!!
[em1][em1]