How to serve static content dynamically in Struts2
in Struts2 it is possible to serve static content like images, JS or CSS files by putting them into resources/static. From this point Struts2 takes care for serving them on HTTP request and everyone, especially my JSPs, are happy.
Now I have to retrieve all this static files from a DB; I get them as byte[]
. The purpose is to exchange the files without redeploying the web application.
Do you have any suggestions how to serve them elegantly? Can I overwrite e.g. some static resource provider? Alterna开发者_运维百科tively, should I provide an action for that? I'm mainly concerned about caching. Is there something else I should be concerned about?
Thanks in advance, any hint is appreciated! :)
Gregor
Create an action to fetch the data from the database and then use the stream
result type. The stream
result will automatically handle setting the appropriate cache headers for the response (caching is turned on by default). You will need to provide the content type and the InputStream
.
For details, check the Javadoc for StreamResult.
精彩评论