I'm using the following code as part of the GWT server-side class (servlet) for GWT-RPC.
private void getImage() {
HttpServletResponse res = this.getThreadLocalResponse();
try {
// Set content type
res.setContentType("image/png");
// Set content size
File file = new File("C:\\Documents and Settings\\User\\image.png");
res.setContentLength((int) file.length());
// Open the file and output streams
FileInputStream in = new FileInputStream(file);
OutputStream out = res.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
The servlet is running when i press a button on the client. I want to use the Image class to load the image into the client but i do not know how to get the url of the image from the servlet to the client's code in order to display it. Is this correct procedure or there is another way? I use GWT for the client and GWT-RPC for client-server communication.