这是我在JSP文件中的Java代码。我正进入(状态
为什么会这样呢?我必须添加一些与Base64Encoder
相关的东西。任何建议将不胜感激。
<%@ page language="java" import="java.io.OutputStream,java.net.HttpURLConnection,java.net.URL,java.util.Collection,org.apache.commons.httpclient.Credentials,org.apache.commons.httpclient.auth.AuthenticationException,org.apache.commons.httpclient.auth.MalformedChallengeException,org.apache.commons.httpclient.params.DefaultHttpParams,org.apache.commons.httpclient.params.HttpParams,org.apache.commons.httpclient.auth.AuthScheme,org.apache.commons.httpclient.auth.AuthPolicy,org.apache.commons.httpclient.HttpClient,org.apache.commons.httpclient.UsernamePasswordCredentials,org.apache.commons.httpclient.auth.AuthScope,org.apache.commons.httpclient.methods.GetMethod,org.w3c.dom.*,javax.xml.parsers.DocumentBuilder,javax.xml.parsers.DocumentBuilderFactory,java.net.*,java.io.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
String a_Url = request.getParameter( "url" ) ;
URL url = new URL (a_Url);
String encoding = Base64Encoder.encode ("test:test");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setRequestProperty ("Authorization", "Basic " + encoding);
InputStream content = (InputStream)connection.getInputStream();
BufferedReader in =
new BufferedReader (new InputStreamReader (content));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
%>
最佳答案
看起来您正在使用Web应用程序中包含的jar中不存在的类。您可以尝试以下吗?如有必要,请进行调整,我只是在查看通用文档,然后将其输入-
[字符串编码= Base64Encoder.encode(“test:test”);]
和
String encoding = new String(
org.apache.commons.codec.binary.Base64.encodeBase64
(org.apache.commons.codec.binary.StringUtils.getBytesUtf8("test:test"))
);
关于java - 无法解析Base64Encoder,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6526883/