例子如下:
pulic class CodeReturn extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException , ServletException {
response.setContentType("application/jar");
ServletContext ctx=getServletContext();
InputStream is=ctx.getResourceAsStream("/bookCode.jar") ;//
Returns the resource located at
the named path as an InputStream object.
int read=0;
byte[] bytes=new byte[1024];
OutputStream os=response.getOuputStream
();// Returns a ServletOutputStream suitable for writing binary data in the response,Provides an output stream for sending binary data to the client. A ServletOutputStream object is normally retrieved via the ServletResponse.getOutputStream() method.
while((read=is.read(bytes)!=-1){
os.write(bytes,0,read);
}
os.flush();
os.close();
}
}