I never done this before. But I 've read a sample.
In your code, you open a Http connection, then you are waiting there.
You should send a GET request and then wait for the image response.
void saveFile(
String strFileName){ try{ URL url = new URL(strImageDownloadPath + strFileName); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); String HTTP_PROXY_USERNAME = System.getProperty("http.proxyUsername"); String HTTP_PROXY_PASSWORD = System.getProperty("http.proxyPassword"); String authString = HTTP_PROXY_USERNAME + ":" + HTTP_PROXY_PASSWORD; String auth = "Basic " + new sun.misc.BASE64Encoder().encode( authString.getBytes() ); connection.setRequestProperty( "Proxy-Authorization", auth ); connection.setDoInput( true );
-- here add some code to send a request
InputStream is =
connection.getInputStream(); objFile = new FileOutputStream(strImageDownloadPath + strFileName); int b; while((b=is.read())!=-1){ objFile.write(b); } is.close(); objFile.close(); }catch(FileNotFoundException fnfe){ System.out.println("FileNotFoundException occured!!!"); }catch(IOException ioe){ }finally{ } }
also, at the server side, you should add the following code in jsp:
response.setContentType("image/jpeg")
Hope it helps.