简体   繁体   English

如何从在JBoss上运行的Spring Web应用程序创建和读取文件?

[英]How to create and read a file from spring web application running on JBoss?

I have a spring web application running on JBoss which is creating a csv file containing a report. 我有一个运行在JBoss上的spring Web应用程序,它正在创建一个包含报告的csv文件。 The application must provide a link to the report when it finish its generation, and the user should be able to download it. 应用程序必须在完成报告生成后提供指向该报告的链接,并且用户应能够下载该报告。

I am thinking to write the file directly inside the war, so then we could read it from the web application. 我正在考虑将文件直接写在战争内部,因此我们可以从Web应用程序中读取它。 But I have some problems to figure out a relative path to write the file in the correct place. 但是我有一些问题要找出在正确位置写入文件的相对路径。

The default path where the file is written is /bin directory in the Jboss application server folder. 写入文件的默认路径是Jboss应用程序服务器文件夹中的/ bin目录。

Which could be the best way to achieve this? 哪一种是实现此目标的最佳方法?

I discourage you from trying to do this - writing files into the internals of JBoss is liable to give unpredictable results, depending on the specific setup of the server. 我不鼓励您尝试这样做-根据服务器的特定设置,将文件写入JBoss的内部可能会产生无法预测的结果。

Instead, I suggest writing the file to a temporary location on the filesystem, independent of JBoss. 相反,我建议将文件写到文件系统上的一个临时位置,与JBoss无关。 Then, write a Spring MVC controller to service requests for the file. 然后,编写一个Spring MVC控制器来处理对该文件的请求。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM