Workaround:
1: Read the picture from the database in the background in a inputstream way:
Public StaticInputStream Getpicinputstream () {String ID= "F304733361E243779B2340AFE20E62BF"; Connection Conn=jdbcutil.getconnection (); PreparedStatement PS=NULL; ResultSet RS=NULL; InputStream is=NULL; String SQL= "Select ZP from Pic_test where id=?"; Try{PS=conn.preparestatement (SQL); Ps.setstring (1, id); RS=Ps.executequery (); if(Rs.next ()) { is= Rs.getblob ("ZP"). Getbinarystream (); } } Catch(SQLException ex) {Logger.getlogger (Test.class. GetName ()). log (Level.severe,NULL, ex); }finally{ Try { if(NULL!=PS) {Ps.close (); } } Catch(SQLException ex) {Logger.getlogger (Test.class. GetName ()). log (Level.severe,NULL, ex); } Try { if(NULL!=RS) {Rs.close (); } } Catch(SQLException ex) {Logger.getlogger (Test.class. GetName ()). log (Level.severe,NULL, ex); } jdbcutil.release (conn); } returnis ; }
2: Create a picture directly in the servlet:
Response.setcontenttype ("Image/jpeg"); InputStream is=Test.getpicinputstream (); if(NULL!=is ) {outputstream OS=Response.getoutputstream (); intLen; byteBuf[] =New byte[1024]; while((Len=is.read (BUF))!=-1) {os.write (buf,0, Len); } is.close (); Os.close (); }
Processing of 3:android Clients
Public classMainactivityextendsActivity {ImageView imgview; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Imgview=(ImageView) Findviewbyid (R.id.imgview); NewImgviewasynctask (). Execute (""); } classImgviewasynctaskextendsAsynctask<string,string,string>{Bitmap Bitmap=NULL; @Overrideprotected voidOnPreExecute () {} @Overrideprotectedstring Doinbackground (String ... strings) {InputStream is=NULL; String result= ""; Try{URL Picurl=NewURL ("Http://192.168.0.165:8084/wisdompm/PicServlet"); HttpURLConnection Conn=(HttpURLConnection) picurl.openconnection (); Conn.setconnecttimeout (10000); Conn.connect (); is=Conn.getinputstream (); if(NULL!=is ) {Bitmap=Bitmapfactory.decodestream (IS); } } Catch(malformedurlexception e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); }finally { Try { if(NULL!=is ) {Is.close (); } } Catch(IOException e) {e.printstacktrace (); } } returnresult; } @Overrideprotected voidOnPostExecute (String s) {if(NULL!=bitmap &&NULL!=Imgview) {Imgview.setimagebitmap (bitmap); } } }}
Test results:
The image is stored in a blob in the background database, and the Android client reads the display