This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See JSP code. It's not working and not throwing any error either. Could anyone help figure out the error?
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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((!=-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:

Hope it helps.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!