构造函数 MultipartRequest(HttpServletRequest, String) 未定义
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论