gpt4 book ai didi

Java - 文件上传问题

转载 作者:行者123 更新时间:2023-11-27 22:48:59 26 4
gpt4 key购买 nike

<分区>

小服务程序

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.*;

public class Apply extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
InputStreamReader input = new InputStreamReader(request.getInputStream());
BufferedReader buffer = new BufferedReader(input);
String line="";
line=buffer.readLine();

System.out.println("Multipart data " + line );

boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if(isMultipart)
{
// upload file
}
else
{
// failed, no input
}
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doPost(request, response);
}
}

JSP。

        <form enctype="multipart/form-data" method="post" action="apply">
<fieldset>
<br/>
<legend>Upload</legend>
<br/>
<label>Select file to upload</label>
<input type="file" name="file" /><br />
<br/>
<a href="apply" class="jUiButton">Submit</a>
</fieldset>
</form>
<script>$(".jUiButton").button()</script>

boolean 值和输入总是验证为 false/null,我不明白为什么。遵循本指南:http://sacharya.com/file-upload/

在 web-inf/lib - 我们有 commons-fileupload-1.2.2.jar 和 commons-io-2.0.1.jar。

有什么想法吗?

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