开发者

Struts2 dynamic action names

The problem is simple, I don't know if has a simple solution: I'm using JPA to persist images to a database. I'm also using Struts 2.

I wrote an action that take the image from the db and sand it to the client.

The problem is that in this way, when people try to download the image on their PC, they have to write a name for the file (default is something like image.action - always 开发者_如何学JAVAthe same).

Thanks


Check out the Content-Disposition HTTP Header to specify the filename of the resource. For example:

Content-Disposition: inline; filename: file.jpg

You can add this to your HttpServletResponse like so:

response.setHeader("Content-Disposition", "inline; filename: file.jpg");


There is another simple way to do this, all you have to do is to setup StreamResult in strut.xml

More detail, reference this page

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜