/*** Download PDF file from seven kn *@paramRequest *@paramResponse *@paramExhiid *@throwsmalformedurlexception*/@RequestMapping ("/loadcanzhanhan") Public voidDownloadnet (httpservletrequest request, HttpServletResponse response,string exhiid)throwsmalformedurlexception{exhimain Exhimain=Exhimainservice.get (EXHIID); String Canzhanhanurl=Exhimain.getcanzhanhanurl (); Try { if(Canzhanhanurl! =NULL&& "". Equals (Canzhanhanurl)) {Pdfutil.downloadzhaozhanhan (response, Canzhanhanurl); } } Catch(Exception e) {e.printstacktrace (); } }
/*** Download the pdf file above seven kn *@paramResponse *@paramCanzhanhanurl Seven the file address on the bull *@throwsException*/ Public Static voidDownloadzhaozhanhan (HttpServletResponse response,string canzhanhanurl)throwsexception{intByteread=0; URL URL=NewURL (Canzhanhanurl); Try{URLConnection conn=url.openconnection (); InputStream instream=Conn.getinputstream (); Servletoutputstream OutputStream=Response.getoutputstream (); Response.setheader ("Content-disposition", "attachment;filename=" + Urlencoder.encode ("brochure. pdf", "UTF-8")); Response.setcontenttype ("Application/force-download"); byte[] buffer =New byte[1024]; while(Byteread=instream.read (buffer))!=-1) {outputstream.write (buffer,0, Byteread); } } Catch(Exception e) {e.printstacktrace (); } }
Download PDF files from seven KN service