构造函数 MultipartRequest(HttpServletRequest, String) 未定义

发布于 2025-01-16 15:34:15 字数 1730 浏览 0 评论 0原文

我有 Netbeans IDE 12.5、macOS BigSur 11.1、JDK 17、Apache Tomcat 10.0.16,我的项目库包含 servlet-api.jar、cos.jar、Java EE 7 API 库 jar 文件。我正在制作一个 servlet 代码,用于通过表单上传图像。我收到错误:

HTTP 状态 500 – 内部服务器错误

类型异常报告

消息无法编译 JSP 类:

描述服务器遇到意外情况,无法满足请求。

异常

org.apache.jasper.JasperException:无法编译 JSP 类:

jsp 文件 [/process.jsp] 中第 [19] 行发生错误 构造函数 MultipartRequest(HttpServletRequest, String) 未定义

这是我的 process.jsp 文件

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

addResource.jsp 页面代码:

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文