简体   繁体   中英

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

My Java web application needs to serve up many static HTML reports.

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.

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
  • 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.

I would personally use a web server, such as Apache, to do this, since my Java applications are always behind Apache. Here is an Apache example:

# 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 . Just be careful about handling file paths supplied in request urls, as the servlet can be vulnerable to directory traversal attack .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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