0

I use Netbeans IDE version 12.5, JDK 17 and tomcat version 10.0.26.I have added cos.jar, mysql-connector-java-8.0.26.jar files in library.I have macOS BigSur 11.1. I created resources folder under the path /BVTechHub/Build/Web/resources where BVTechHub is project name. I wanted to create jsp file to upload images but is continuously getting the error:

Type Exception Report

Message Unable to compile class for JSP:

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [19] in the jsp file: [/process.jsp] The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required .class files

An error occurred at line: [19] in the jsp file: [/process.jsp] The constructor MultipartRequest(HttpServletRequest, String) refers to the missing type HttpServletRequest

Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:213) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:498) org.apache.jasper.compiler.Compiler.compile(Compiler.java:397) org.apache.jasper.compiler.Compiler.compile(Compiler.java:367) org.apache.jasper.compiler.Compiler.compile(Compiler.java:351) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:380) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:328) jakarta.servlet.http.HttpServlet.service(HttpServlet.java:777) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Note The full stack trace of the root cause is available in the server logs.

The code of addResource.jsp is as follows:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File Upload Demo</title>
</head>
<body>
    <center>
        <form method="post" action="process.jsp" enctype="multipart/form-data">
            Select file to upload:
            <input type="file" name="upload" />
            <br/><br/>
            <input type="submit" value="Upload" />
        </form>
    </center> 
</body> 
</html>

The code for process.jsp is:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>

<body>
    <%
            String root=getServletContext().getRealPath("resources");
            MultipartRequest m =new MultipartRequest(request,root);
            out.print("File uploaded successfully");
    %>
</body></html>

Please help me resolve this error. Thank you in advance for helping me.

Vishu
  • 1
  • 1
  • 2
    Tomcat 10 is JakartaEE not JavaEE. The packages have changed, if you are using libraries that don't support JakartaEE you cannot use Tomcat 10. Downgrade to Tomcat9. Or ditch the OReily file upload library and use the plain Servlet variant for file uploading (which is a bit harder to use). – M. Deinum Mar 24 '22 at 12:20
  • I added servlet-api.jar and these errors were removed but now I am getting a new error:The constructor MultipartRequest(HttpServletRequest, String) is undefined – Vishu Mar 24 '22 at 12:55
  • Thank you so much @OlafKock for providing me the link but unfortunately its not having the answer to my question since I am importing OReily rather than javax packages. – Vishu Mar 24 '22 at 13:05
  • 1
    The comments above, as well as the linked post provide your answer: Use Tomcat 9 or ditch the library you use (which uses the javax packages). Even the error message clearly states it: _The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required .class files_ – Olaf Kock Mar 24 '22 at 13:19
  • Adding the api isn't going to solve anything, Tomcat10 still doesn't support JavaEE. – M. Deinum Mar 24 '22 at 13:24

0 Answers0