I have uploaded images to server directory in jboss. Path is standalone/data/.. Now,How to get images from server in GWT.??
-
I did this and it worked: http://stackoverflow.com/questions/6491025/how-to-get-image-with-servlet-and-display-it-using-gwt-image-class – Bruno_Ferreira Oct 11 '13 at 10:08
2 Answers
You may simply create a new Image()
and pass the path to the image (if it is accessable by a browser). If it is ot accessable, you will need to create a simple Servlet, that reads the file fomr the disk, and writes it out to the browser.

- 15,850
- 5
- 43
- 79
-
I have tried to create a servlet and read images from that but i can't. – Samir Savasani Oct 11 '13 at 07:16
-
1I've added a link to a Servlet, that will deliver a File from the Filesystem. You will have to change some parts of hte Servlet, but I think this will be helpful. – Christian Kuetbach Oct 11 '13 at 08:42
-
What's the issue concerning to the Servlet you have created? it is properly declared in web.xml and mapped into it? Can you access it by e.g. a web browser? are there any exception that your browser would be throwing? – Oct 11 '13 at 11:48
There are multiple ways but i find out this 2 ways to upload the image file and get back.
1) upload it on destination location using fileItem.write(tempFile);
and get back using
File file = new File(filename);
response.setContentLength((int) file.length());
FileInputStream in = new FileInputStream(file);
OutputStream out = response.getOutputStream();
byte[] buf = new byte[1024];
int count = 0;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}
in.close();
out.close();
handle that response at client side..
2) Upload is same using FileItem.write
If it is in war or project folder then you can access it directly by specifying URL which you access that site.
like, if you war/project folder is "ImageUpload.war" and access link is :- "http://samirsavasani.com:8888/" You have uploaded file in it like "ImageUpload.war"-"Images"-YOUR UPLOADED IMAGES then you can access it just like.. :- "http://samirsavasani.com:8888/Images/YOUR IMAGE NAME"

- 3,847
- 7
- 42
- 67

- 352
- 3
- 8