Base64Encoder无法解析 [英] Base64Encoder cannot be resolved
本文介绍了Base64Encoder无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我在JSP文件中的Java代码。我正在
This is my Java code in a JSP file. I am getting
无法解析Base64Encoder。
Base64Encoder cannot be resolved.
为什么会这样?我必须添加与 Base64Encoder
相关的内容。任何建议将不胜感激。
Why is it so? I have to add something related to Base64Encoder
. Any suggestions will be appreciated.
<%@ 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中。你可以试试以下吗?如果有必要进行调整,我只是查看公共文档并输入 -
Looks like you are using a class that does not exist in a jar you have included in the web application. Can you try the following? Make adjustments if necessary, I am just looking at the documentation for commons and typing this out --
- 转到 http://commons.apache.org/codec/index.html 并阅读那里的信息
- 现在转到 http://commons.apache.org/codec/download_codec .cgi 并下载zip文件
- 解压缩jar文件并将其复制到Web应用程序的lib目录中
- 替换
行[String encoding = Base64Encoder.encode(test:test);]
- Go to http://commons.apache.org/codec/index.html and read through the information there
- Now go to http://commons.apache.org/codec/download_codec.cgi and download the zip file
- Extract out the jar file and copy it to the lib directory of your web application
- Replace the line [String encoding = Base64Encoder.encode ("test:test");]
with
String encoding = new String(
org.apache.commons.codec.binary.Base64.encodeBase64
(org.apache.commons.codec.binary.StringUtils.getBytesUtf8("test:test"))
);
这篇关于Base64Encoder无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文