无法解析Base64Encoder

这是我在JSP文件中的Java代码。我正进入(状态

无法解析Base64Encoder。

为什么会这样呢?我必须添加与相关的内容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中不存在的类。您可以尝试以下吗?如有必要,请进行调整,我只是在查看通用文档,然后将其输入-

  1. 转到http://commons.apache.org/codec/index.html并阅读那里的信息
  2. 现在转到http://commons.apache.org/codec/download_codec.cgi并下载zip文件
  3. 解压缩jar文件并将其复制到Web应用程序的lib目录中
  4. 替换行[String encoding = Base64Encoder.encode(“ test:test”);]

String encoding = new String(

org.apache.commons.codec.binary.Base64.encodeBase64

(org.apache.commons.codec.binary.StringUtils.getBytesUtf8("test:test"))

);

以上是 无法解析Base64Encoder 的全部内容, 来源链接: utcz.com/qa/415484.html

回到顶部