简体   繁体   English

无法将文件保存在Linux服务器上运行的tomcat Webapp中

[英]Can't save file in tomcat webapp running on a linux server

Im currently debugging a webapp , where the user is supposed to upload a file which is then stored temporarily on the server and send via E-Mail to an administrator. 我目前正在调试一个webapp ,用户应该在其中上载一个文件,然后将该文件临时存储在服务器上并通过电子邮件发送给管理员。

The app runs on a tomcat 8 in a linux server environment. 该应用程序在Linux服务器环境中的tomcat 8上运行。 The class from where the error occurs looks like follows: 发生错误的类如下所示:

@Service
public class BugReportBo implements IBugReportBo {

  ...

  @Value("${app.temp.folder}")
  private Resource temp;

  ...

  private File byteArrayToFile(final byte[] lob, final String string) throws IOException {
    final int locatorStartPos = 6;
    String uri = temp.getURI().toString().substring(locatorStartPos);

    //uri: var/lib/tomcat/webapps/prototype/res/temp/
    //string: temp0.jpg

    // convert array of bytes into file
    File f = new File(uri + string);
    FileOutputStream fileOuputStream = new FileOutputStream(uri + string);
    fileOuputStream.write(lob);
    fileOuputStream.close();
    return f;
  }
}

The error is thrown from FileOutputStream fileOuputStream = new FileOutputStream(uri + string); FileOutputStream fileOuputStream = new FileOutputStream(uri + string);抛出错误FileOutputStream fileOuputStream = new FileOutputStream(uri + string); .

The Exception is a FileNotFoundException (message:"var/lib/tomcat/webapps/prototype/res/temp/temp0.jpg (Datei oder Verzeichnis nicht gefunden)"). 异常是FileNotFoundException (消息:“ var / lib / tomcat / webapps / prototype / res / temp / temp0.jpg(日期或日期))”。

Everything seems to be ok to me as the folder is where it is supposed to be and the path seems to be fine as well. 一切似乎对我来说还可以,因为该文件夹应该在该文件夹中,并且路径似乎也不错。

Any ideas? 有任何想法吗?

var/lib/tomcat/webapps/prototype/res/temp/temp0.jpg var / lib / tomcat / webapps / prototype / res / temp / temp0.jpg

You forget the first '/', so the path is understand like a relative path, instead of an absolute path. 您会忘记第一个“ /”,因此该路径像相对路径一样被理解,而不是绝对路径。

/var/lib/tomcat/webapps/prototype/res/temp/temp0.jpg /var/lib/tomcat/webapps/prototype/res/temp/temp0.jpg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Webapp在Tomcat中找不到文件,但系统上存在路径 - Webapp can't find file in Tomcat but path exists on system Webapp在本地tomcat7上运行,但不在Linux tomcat7上运行 - Webapp is running on local tomcat7 but not on linux tomcat7 使用IntelliJ运行Tomcat-无法启动服务器 - Running tomcat with IntelliJ - can't start the server 在Linux服务器上运行的Tomcat。 从此服务器发出请求时无法获得响应,但是在发出远程请求时却可以 - Tomcat running on linux server. Can't get response while making request from this server, but can while making remote requests war webapp中Tomcat服务器绝对文件访问 - Tomcat server absolute file access in war webapp Tomcat无法在Ubuntu中加载我的Web应用程序 - tomcat can't load my webapp in ubuntu 在Apache Tomcat服务器上运行时,为什么无法访问.properties文件? - Why can't acess .properties file when running on Apache Tomcat Server? 如何以编程方式确定运行webapp的哪个(负载平衡)tomcat服务器 - How to programmatically determine which (load balanced) tomcat server the webapp is running on 在tomcat的lib中的jar在我的webapp中看不到属性文件 - A jar in tomcat's lib can't see a properties file in my webapp 如何读取在 apache tomcat 中运行的 web 应用程序的清单文件? - How do I read the manifest file for a webapp running in apache tomcat?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM