gpt4 book ai didi

java - 使用 request.getpart 时出现空指针异常

转载 作者:行者123 更新时间:2023-12-02 09:15:13 25 4
gpt4 key购买 nike

我有两个jsp文件。在 test3.jsp 中,我选择一个文件并输入版本,然后显示它。
test3.jsp

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form action="test2.jsp" method="post"
enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<input type="text" name="version"/>
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>

test2.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*"
%><%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.lang.System"%>
<%@page import=" javax.servlet.*" %>
<%@page import="javax.servlet.http.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body><table>
</table>
</body>
</html>
<%
// Part filePart = request.getPart("file"); // Retrieves <input type="file" name="file">
// String fileName = filePart.getSubmittedFileName();
out.println("<html>");
out.println("<head>");
out.println("</head>");
out.println("<body>"+request.getPart("version").getContentType());
out.println("</body>");
out.println("</html>");
%>

上传部分尚未完成,仅针对上面的代码,我遇到了以下错误。

org.apache.jasper.JasperException: java.lang.NullPointerException at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:473) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.jsp.JspFileHandler.handleRequest(JspFileHandler.java:32) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest Caused by: java.lang.NullPointerException at org.apache.jsp.test2_jsp._jspService(test2_jsp.java:124) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:433) ... 42 more

任何人都可以告诉我出了什么问题吗?谢谢。

最佳答案

您正在查找“文本”字段(版本)中的部分,请尝试使用"file"

关于java - 使用 request.getpart 时出现空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59047992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com