开发者

In html <a href> tag, how to call servlet before opening file dialog for download (save as)?

I am developing a web-app where I want to provide a download link to users - so the开发者_如何学编程y can download a zip file from my server. Now, my requirement is that I want to execute some processing logic contained in a servlet before displaying the file dialog to the user for 'zip' files.

So If I write

<a href="abc.zip".......>

then it opens a file dialog asking the user to select the location where this file can be saved

But if I want a servlet's doGet method to do some preprocessing - say like building the zip file , then how can I first call the servlet and then open the file dialog.

Will the following snippet work?

 <a href="MyHandlerServlet;abc.zip".......>

Thanks for your help !!


I would rather pass the filename as pathinfo instead of request parameter, e.g.

<a href="MyHandlerServlet/abc.zip">

Otherwise a certain widely used webbrowser developed by a team in Redmond (cough) would use MyHandlerServlet as filename during Save As. When passing the filename as pathinfo, you can obtain the requested file in the servlet by:

String filename = request.getPathInfo();

You only need to map the servlet on /MyHandlerServlet/* instead of /MyHandlerServlet. Also see this basic servlet example.


 <a href="MyHandlerServlet?file=abc.zip">

The servlet would need to respond to the request with the zip file.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜