gpt4 book ai didi

java - JSP如何获取JSP中文件的完全限定名称

转载 作者:行者123 更新时间:2023-12-01 14:25:52 24 4
gpt4 key购买 nike

我正在尝试使用 JSP 上传文件

<form action="EdgeWarUpload" method="post"
enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />

其中 EdgeWarUpload 是一个 servlet。用户正在浏览并选择要上传的文件。我想要 servlet EdgeWarUpload 中带有文件名(路径名+文件名)的完全限定路径来创建 BufferedInputStream。但是我无法获取请查收并回复。

最佳答案

<html>  
<header></header>
<body>
<form method="POST" action="upload.do">
escolha o arquivo para fazer upload:
<input type="file" name="ctrupload"><br>
<input type="submit" name="submit" value="enviar...">
</form>
</body>
</html>

试试这个

public class Uploader extends HttpServlet {  
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletInputStream sis = request.getInputStream();

byte[] b = new byte[request.getContentLength()];

System.out.println(request.getContentLength());

sis.read(b,0,b.length);

FileOutputStream fos = new FileOutputStream("Teste.jpg");
fos.write(b);

sis.close();
fos.flush();
fos.close();
}
}

你确实不需要完全限定的路径

关于java - JSP如何获取JSP中文件的完全限定名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17186500/

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