Base64Encoder could not be resolved

This is my Java code in a JSP file. I get

Base64Encoder could not be resolved.

Why is that? I need to add something related to Base64Encoder . Any suggestions would 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); } %> 
+7
source share
4 answers

It looks like you are using a class that does not exist in the bank that you included in the web application. Can you try the following? Make corrections if necessary, I just look at the documentation for general use and type it -

from

 String encoding = new String( org.apache.commons.codec.binary.Base64.encodeBase64 (org.apache.commons.codec.binary.StringUtils.getBytesUtf8("test:test")) ); 
+15
source

I suspect that you are not using a standalone JRE instead of the one included in the JDK.

  • Right-click your project and select Build Path β†’ Configure Build Path
  • In the "Libraries" section, click on an existing JRE, and then click "Delete."
  • Click Add Library β†’ JRE Library β†’ Done

The class should now be allowed.

+11
source

You may need to import or specify the fully qualified class name for Base64Encoder

+1
source

I do not see namespace inclusion here for Base64Encoder. Try adding "com.oreilly.servlet" to your import.

+1
source

All Articles