| Author |
jar file download
|
Naresh Chaurasia
Ranch Hand
Joined: May 18, 2005
Posts: 309
|
|
Hi, I have taken the following code from HFSJ that is used for downloading jar file.When the above servlet is called,the file is downloaded with name InputOutputStream. Is it possible that when the download starts, it is done with extension jar(without myself explicitly specify it during the download). public class InputOutputStream extends HttpServlet { public void init(ServletConfig config)throws ServletException{ super.init(config); } public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("application/jar"); InputStream is = getServletContext().getResourceAsStream("/archive.jar"); int iRead=0; byte b[] = new byte[1024]; OutputStream os = res.getOutputStream(); while( (iRead=is.read(b) ) != -1) { os.write(b,0,iRead); } os.flush(); os.close(); }//end of doGet public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { doGet(req, res); } }
|
SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
|
 |
Anand Wadhwani
Ranch Hand
Joined: Mar 21, 2005
Posts: 151
|
|
Put the following line immediately after setContentType(): This line will make the browser aware of the name to use for downloading the stram. Therefore the browser will display the download dialog box with the given name 'Archive.jar' by default. Hope this helps. [ June 17, 2005: Message edited by: Anand Wadhwani ]
|
SCWCD 1.4<br />---------------------<br />Ability is what you're capable of. <br />Motivation determines what you do. <br />Attitude determines how well you do it.<br />---------------------
|
 |
Naresh Chaurasia
Ranch Hand
Joined: May 18, 2005
Posts: 309
|
|
Hi Anand, thnx. It is woking fine.
|
 |
 |
|
|
subject: jar file download
|
|
|