0

I have Netbeans IDE 12.5, macOS BigSur 11.1, JDK 17, Apache Tomcat 10.0.16 and my project library contains servlet-api.jar, cos.jar, Java EE 7 API library jar files. I am making a servlet code for uploading of images through form. I am getting the error:

HTTP Status 500 – Internal Server 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 constructor MultipartRequest(HttpServletRequest, String) is undefined

This is my process.jsp file

<%@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>

The addResource.jsp page code:

<%@page import= "java.util.Map" %>
<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>
James Z
  • 12,209
  • 10
  • 24
  • 44
Vishu
  • 1
  • 1
  • Oh, wow. The old O'Reilly sample code for multipart form requests. You don't want to use that 20-year-old code. Servlet containers now handle multi-part form-data natively and have done so for years. You should use the Servlet API for fetching multipart data and not use the O'Reilly stuff anymore. Search the current Servlet API javadoc for `HttpServletRequest` and the `getParts` method. – Christopher Schultz Mar 24 '22 at 18:28
  • 1
    Does this answer your question? [The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required .class files in netbeans IDE in macOs](https://stackoverflow.com/questions/71602347/the-type-javax-servlet-http-httpservletrequest-cannot-be-resolved-it-is-indirec) (it's not _exactly_ that, but a follow up problem of your other question. Use tomcat 9! And follow Christopher's advice) – Olaf Kock Mar 24 '22 at 18:57

0 Answers0