gpt4 book ai didi

jsp - 将文件从 Windows 客户端上传到 Linux tomcat 服务器时出现 FileNotFoundException

转载 作者:行者123 更新时间:2023-11-28 23:57:33 25 4
gpt4 key购买 nike

<分区>

我最近刚刚在运行 tomcat 的 linux 服务器上安装了我的 Web 应用程序。在我的 Windows 计算机上本地运行应用程序允许我毫无问题地上传 XML 文件,但现在它在 tomcat 服务器上,我不断收到 NullPointerExceptions。

这是接收文件的 servlet 部分:

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, ParserConfigurationException, SAXException, ResponseException {
response.setContentType("text/html;charset=UTF-8");

//Create path components to save the file
final Part filePart = request.getPart("XMLFile"); // Retrieves <input type="file" name="XMLFile">
final String path = "/opt/tomcat/bin";
final String fileName = getFileName(filePart);

OutputStream outStream = null;
InputStream fileContent = null;
final PrintWriter out = response.getWriter();

try {
//File xmlFile = new File(path + File.separator + fileName);
File xmlFile = new File(fileName);
outStream = new FileOutputStream(xmlFile);
fileContent = filePart.getInputStream();
...

“File xmlFile = new File(fileName)”行在后面的 catch 语句中抛出 FileNotFoundException。我尝试了很多不同的可能性,但我找不到错误。

通过一些代码行,我最终得到的文件路径是“opt/tomcat/bin/(我的 xml 文件的名称)”,有时它是“opt/tomcat/bin/opt/tomcat/bin/” (我的 xml 文件的名称)”,但它们都不起作用。

知道错误可能是什么吗?

这是我的 JSP 页面上处理文件上传的表单:

<form style="text-align: center" style="position: relative" style="right: auto" style="left: auto" action="upload" method="post" enctype="multipart/form-data">

<h3>Upload your iTunes library</h3>
<input style="margin: 0 auto" name="XMLFile" id="file" type="file"/>
<br>
<input type="submit" value="Submit" formmethod="post" formaction="GetItunesLibrary"/>
</form>

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