0

我正在编写 Java Web 应用程序。我正在尝试使用 multipart-config 上传文件,但是当我从请求中调用 getPart() 时出现 NullPointerException。

我正在为 JavaEE 使用 Tomcat 8 和 Eclipse。

这是servlet代码的一部分:

...
 @Override
    protected void doPost(
            HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException {

        Part filePart = request.getPart("json_file");
        InputStream fileContent = filePart.getInputStream();
...

这是来自 JSP 文件的表单:

...
<form action="${pageContext.request.contextPath}/processJson" method="POST" enctype="multipart/form-data">
            <label for="json_file">Файл:</label>
            <input type="file" name="json_file" id="json_file" accept=".json" />
            <br /><br />
            <div class="submit-container">
                <input type="submit" name="ready" id="ready" value="Загрузить" />
            </div>
        </form>
...
4

0 回答 0