简体   繁体   English

如何从Java Web应用程序托管用户生成的HTML页面?

[英]How to host user-generated HTML pages from Java web app?

My Java web application needs to serve up many static HTML reports. 我的Java Web应用程序需要提供许多静态HTML报告。

The reports are generated on-demand using a 3rd party application based on user's inputs. 使用基于用户输入的第三方应用程序按需生成报告。 The reports will always be different from run to run, so they can't be cached. 每次运行的报告将始终不同,因此无法缓存它们。 The reports include multiple HTML pages (including JS and CSS pages), and relative links between files. 这些报告包括多个HTML页面 (包括JS和CSS页面)以及文件之间的相对链接。

What's the easiest way to serve up these reports to the front-end user? 将这些报告提供给前端用户的最简单方法是什么?

The reports don't need to stick around -- they can be deleted after a set time or after the user logs out. 这些报告不需要保留-可以在设置的时间之后或用户注销后将其删除。

I'm using: 我正在使用:

  • Tomcat 7 雄猫7
  • Spring framework 春季框架

Here is a similar example : 这是一个类似的例子

Suppose the web app is an online IDE, and you'd like to occasionally generate and display Javadoc pages for the project. 假设该Web应用程序是一个在线IDE,并且您希望偶尔生成并显示该项目的Javadoc页面。

I would personally use a web server, such as Apache, to do this, since my Java applications are always behind Apache. 我个人会使用Web服务器(例如Apache)来执行此操作,因为我的Java应用程序始终位于Apache之后。 Here is an Apache example: 这是一个Apache示例:

# Serve /path/to/html/files/ with static files stored at /var/path/to/files/
ProxyPass /path/to/html/files/ !
Alias /path/to/html/files/ /var/path/to/files/

# Proxy / to Java application at localhost:8080
ProxyPass / http://localhost:8080/

If you must use a pure Java solution, you could try to set up a file download servlet, such as this one by BalusC . 如果必须使用纯Java解决方案,则可以尝试设置一个文件下载servlet, 例如BalusC所设计的 Just be careful about handling file paths supplied in request urls, as the servlet can be vulnerable to directory traversal attack . 请注意处理请求url中提供的文件路径,因为servlet容易受到目录遍历攻击

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

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