开发者

Specify image name in "on the fly" java image generation

I have some java code that generates an image from scratch.

I also have a servlet that serves the image according to some parameters (fyi, it is QR Code generation).

I would like to specify a name for this image in case somebody right-click and save it. THe browser currently takes the relative URL as a name (ie, generate), and there is no extension.

Do you have any idea ?

开发者_如何学编程

Thanks, Alexis.


Use a nice url to encode your image.
I suppose now you're doing something like

generateServlet?product=27&query=5

instead, map it to

images/qr/product27_q5.png

This way, the browser will only see the nice url and propose that as a file name. It also hides your implementation more.

Just map your servlet to images/qr/* and then use a regular expression to extract the actual parameters from the requested path.

You could even generate different image types depending on the extension provided :)


    resp.setContentType("image/jpg");
    resp.setHeader( "Content-Disposition", "attachment; filename=\"" + your_filename + "\"" );
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜