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.