aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jar file download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jar file download" Watch "jar file download" New topic
Author

jar file download

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 356
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: 356
Hi Anand,
thnx. It is woking fine.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jar file download
 
Similar Threads
doGet() and doPost()
Servlets example
New to servlets
why error in setHeader()
HTTP method GET is not supported by this URL