1

I tried to run my web project in a web browser. while running one of the JSP file I encountered following Unable to compile class for JSP:

screenshot of internal server error

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43
  • 1
    Could you copy the text in your error and paste it into a code block, rather than paste an image? – Jad Jun 16 '21 at 18:27

1 Answers1

0

First let me remark, that using scriptlets <% ... %> in JSP pages is deprecated since about 20 years (see this question on how to replace them).

In your JSP page you are using javax.xml.bind.DatatypeConverter, which is part of JAXB. JAXB was removed from Java SE 9 and later versions. However since Java SE 8 you can use Base64.Encoder to encode a byte array using Base 64.

Therefore replace:

<%@page import="javax.xml.bind.DatatypeConverter"%>
...
String b64 = DatatypeConverter.printBase64Binary(imageInByteArray);

with

<%@page import="java.util.Base64"%>
...
String b64 = Base64.getEncoder().encodeToString(imageInByteArray);
Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43
  • i replaced this code <%@page import="javax.xml.bind.DatatypeConverter"%> ... " String b64 = DatatypeConverter.printBase64Binary(imageInByteArray); with the code you wrote above but after running it in the server it showed same error ,upon checking the jsp.java file . i saw string b64=DatatypeConverter.printBase64Binary(imageInByteArray); reappear again – Rohit chandran Jun 17 '21 at 02:59
  • Did you replace it in `stationview.jsp` or `stationview_jsp.java`? The latter is generated by Tomcat and regularly overwritten. – Piotr P. Karwasz Jun 17 '21 at 03:24