Discussion:
How to handle image/gif response
zhangj5
2009-11-19 12:01:19 UTC
Permalink
Hi all,
I have a question about how to handle image/gif type response on
client side, any suggestion will be great.
There is a service which responds for retrieving image (only one each
time at the moment) from database. The code is something like,

JDBC Connection
Construct MYSQL query.
Execute query
If has ResultSet, retrieve first one {
image = rs.getBlob("img"); //save image into Blob image, “img” is the
only entity in the image table.
}

Then,
response.setContentType("image/gif"); //set response type
InputStream in = image.getBinaryStream(); //output Blob image to
InputStream
int bufferSize = 1024; //buffer size
byte[] buffer = new byte[bufferSize]; //initial buffer
int length =0;
while ((length = in.read(buffer)) != -1) {//read length data from
inputstream and store into buffer
out.write(buffer, 0, length); //write into
ServletOutputStream
}
in.close();
out.flush(); //write out

The code on client side
....
imgform.setAction(GWT.getModuleBaseURL() + "serviceexample/
ImgRetrieve");
....
ClickListener {
OnClick, then imgform.submit();
}


formHandler {

onSubmit, form validation

onSubmitComplete
??????? //handle response, and display image
Here is my question, i had tried
Image img = new Image(GWT.getHostPageBaseURL()
+"serviceexample/ImgRetrieve");
mg.setSize("300", "300");
imgpanel.add(img);
but i only got a non-displayed image with 300X300 size.
}

So, how should i handle the responde in this case?


Thanks,

--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to google-web-toolkit+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=.
Martin Trummer
2009-11-19 19:22:15 UTC
Permalink
what are you trying to do?

what is the form good for?
does it upload the image and afterwards you want to display this
uploaded image?
Post by zhangj5
Hi all,
I have a question about how to handle image/gif type response on
client side, any suggestion will be great.
There is a service which responds for retrieving image (only one each
time at the moment) from database. The code is something like,
JDBC Connection
Construct MYSQL query.
Execute query
If has ResultSet, retrieve first one {
image = rs.getBlob("img"); //save image into Blob image, “img” is the
only entity in the image table.
}
Then,
response.setContentType("image/gif"); //set response type
InputStream in = image.getBinaryStream();       //output Blob image to
InputStream
int bufferSize = 1024;  //buffer size
byte[] buffer = new byte[bufferSize];           //initial buffer
int length =0;
while ((length = in.read(buffer)) != -1) {//read length data from
inputstream and store into buffer
        out.write(buffer, 0, length);           //write into
ServletOutputStream}
in.close();
out.flush();            //write out
The code on client side
....
imgform.setAction(GWT.getModuleBaseURL() + "serviceexample/
ImgRetrieve");
....
ClickListener {
OnClick, then imgform.submit();
}
formHandler {
        onSubmit, form validation
        onSubmitComplete
            ??????? //handle response, and display image
        Here is my question, i had tried
        Image img = new Image(GWT.getHostPageBaseURL()
+"serviceexample/ImgRetrieve");
        mg.setSize("300", "300");
        imgpanel.add(img);
        but i only got a non-displayed image with 300X300 size.
}
So, how should i handle the responde in this case?
Thanks,
--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to google-web-toolkit+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=.
Martin Trummer
2009-11-19 19:33:36 UTC
Permalink
if you only want to display an image there's no need for a form

this might be useful:
http://bit.ly/2Wgvtm
Post by Martin Trummer
what are you trying to do?
what is the form good for?
does it upload the image and afterwards you want to display this
uploaded image?
Post by zhangj5
Hi all,
I have a question about how to handle image/gif type response on
client side, any suggestion will be great.
There is a service which responds for retrieving image (only one each
time at the moment) from database. The code is something like,
JDBC Connection
Construct MYSQL query.
Execute query
If has ResultSet, retrieve first one {
image = rs.getBlob("img"); //save image into Blob image, “img” is the
only entity in the image table.
}
Then,
response.setContentType("image/gif"); //set response type
InputStream in = image.getBinaryStream();       //output Blob image to
InputStream
int bufferSize = 1024;  //buffer size
byte[] buffer = new byte[bufferSize];           //initial buffer
int length =0;
while ((length = in.read(buffer)) != -1) {//read length data from
inputstream and store into buffer
        out.write(buffer, 0, length);           //write into
ServletOutputStream}
in.close();
out.flush();            //write out
The code on client side
....
imgform.setAction(GWT.getModuleBaseURL() + "serviceexample/
ImgRetrieve");
....
ClickListener {
OnClick, then imgform.submit();
}
formHandler {
        onSubmit, form validation
        onSubmitComplete
            ??????? //handle response, and display image
        Here is my question, i had tried
        Image img = new Image(GWT.getHostPageBaseURL()
+"serviceexample/ImgRetrieve");
        mg.setSize("300", "300");
        imgpanel.add(img);
        but i only got a non-displayed image with 300X300 size.
}
So, how should i handle the responde in this case?
Thanks,
--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to google-web-toolkit+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=.
zhangj5
2009-11-20 11:40:31 UTC
Permalink
Maybe I did not explain my question correctly.
Actually, my application is to create a registered user login
interface. Registered user has photo stored in DB (uploaded when
registration ), and once user login successfully, his/her photo will
be retrieved from DB and displayed, so using the combination of form
submit and GWT is the only solution I have found, just wondering if
there are any other techniques can be used in this case, as this is my
fist GWT application.
I had tried to display image by using
<pre>Image img = new Image( “google.com/intl/en_AL/images/
logo.gif” );</pre>
,which is working as expected.
Since my image is stored in ServletOutputStream,
I tried to use<pre>Image img = new Image (GWT.getHostPageBaseURL() +
"serviceexample/ImgRetrieve"); </pre>
But image is not displayed.
Post by Martin Trummer
if you only want to display an image there's no need for a form
this might be useful:http://bit.ly/2Wgvtm
Post by Martin Trummer
what are you trying to do?
what is the form good for?
does it upload the image and afterwards you want to display this
uploaded image?
Post by zhangj5
Hi all,
I have a question about how to handle image/gif type response on
client side, any suggestion will be great.
There is a service which responds for retrieving image (only one each
time at the moment) from database. The code is something like,
JDBC Connection
Construct MYSQL query.
Execute query
If has ResultSet, retrieve first one {
image = rs.getBlob("img"); //save image into Blob image, “img” is the
only entity in the image table.
}
Then,
response.setContentType("image/gif"); //set response type
InputStream in = image.getBinaryStream();       //output Blob image to
InputStream
int bufferSize = 1024;  //buffer size
byte[] buffer = new byte[bufferSize];           //initial buffer
int length =0;
while ((length = in.read(buffer)) != -1) {//read length data from
inputstream and store into buffer
        out.write(buffer, 0, length);           //write into
ServletOutputStream}
in.close();
out.flush();            //write out
The code on client side
....
imgform.setAction(GWT.getModuleBaseURL() + "serviceexample/
ImgRetrieve");
....
ClickListener {
OnClick, then imgform.submit();
}
formHandler {
        onSubmit, form validation
        onSubmitComplete
            ??????? //handle response, and display image
        Here is my question, i had tried
        Image img = new Image(GWT.getHostPageBaseURL()
+"serviceexample/ImgRetrieve");
        mg.setSize("300", "300");
        imgpanel.add(img);
        but i only got a non-displayed image with 300X300 size.
}
So, how should i handle the responde in this case?
Thanks,
--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to google-web-toolkit+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=.
Martin Trummer
2009-11-20 14:52:14 UTC
Permalink
Image img = new Image (GWT.getHostPageBaseURL() +"serviceexample/
ImgRetrieve");
that's the way to go

ImgRetrieve should be a servlet that sends back the image
if it receives a get request

that's explained in the link of my last post
Post by zhangj5
Maybe I did not explain my question correctly.
Actually, my application is to create a registered user login
interface. Registered user has photo stored in DB (uploaded when
registration ), and once user login successfully, his/her photo will
be retrieved from DB and displayed, so using the combination of form
submit and GWT is the only solution I have found, just wondering if
there are any other techniques can be used in this case, as this is my
fist GWT application.
I had tried to display image by using
<pre>Image img = new Image( “google.com/intl/en_AL/images/
logo.gif” );</pre>
,which is working as expected.
Since my image is stored in ServletOutputStream,
I tried to use<pre>Image img = new Image (GWT.getHostPageBaseURL() +
"serviceexample/ImgRetrieve"); </pre>
But image is not displayed.
Post by Martin Trummer
if you only want to display an image there's no need for a form
this might be useful:http://bit.ly/2Wgvtm
Post by Martin Trummer
what are you trying to do?
what is the form good for?
does it upload the image and afterwards you want to display this
uploaded image?
Post by zhangj5
Hi all,
I have a question about how to handle image/gif type response on
client side, any suggestion will be great.
There is a service which responds for retrieving image (only one each
time at the moment) from database. The code is something like,
JDBC Connection
Construct MYSQL query.
Execute query
If has ResultSet, retrieve first one {
image = rs.getBlob("img"); //save image into Blob image, “img” is the
only entity in the image table.
}
Then,
response.setContentType("image/gif"); //set response type
InputStream in = image.getBinaryStream();       //output Blob image to
InputStream
int bufferSize = 1024;  //buffer size
byte[] buffer = new byte[bufferSize];           //initial buffer
int length =0;
while ((length = in.read(buffer)) != -1) {//read length data from
inputstream and store into buffer
        out.write(buffer, 0, length);           //write into
ServletOutputStream}
in.close();
out.flush();            //write out
The code on client side
....
imgform.setAction(GWT.getModuleBaseURL() + "serviceexample/
ImgRetrieve");
....
ClickListener {
OnClick, then imgform.submit();
}
formHandler {
        onSubmit, form validation
        onSubmitComplete
            ??????? //handle response, and display image
        Here is my question, i had tried
        Image img = new Image(GWT.getHostPageBaseURL()
+"serviceexample/ImgRetrieve");
        mg.setSize("300", "300");
        imgpanel.add(img);
        but i only got a non-displayed image with 300X300 size.
}
So, how should i handle the responde in this case?
Thanks,
--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to google-web-toolkit+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=.
zhangj5
2009-11-20 15:12:42 UTC
Permalink
Ok, i will give it a go, thanks Martin.
Post by Martin Trummer
Image img = new Image (GWT.getHostPageBaseURL() +"serviceexample/
ImgRetrieve");
that's the way to go
ImgRetrieve should be a servlet that sends back the image
if it receives a get request
that's explained in the link of my last post
Post by zhangj5
Maybe I did not explain my question correctly.
Actually, my application is to create a registered user login
interface. Registered user has photo stored in DB (uploaded when
registration ), and once user login successfully, his/her photo will
be retrieved from DB and displayed, so using the combination of form
submit and GWT is the only solution I have found, just wondering if
there are any other techniques can be used in this case, as this is my
fist GWT application.
I had tried to display image by using
<pre>Image img = new Image( “google.com/intl/en_AL/images/
logo.gif” );</pre>
,which is working as expected.
Since my image is stored in ServletOutputStream,
I tried to use<pre>Image img = new Image (GWT.getHostPageBaseURL() +
"serviceexample/ImgRetrieve"); </pre>
But image is not displayed.
Post by Martin Trummer
if you only want to display an image there's no need for a form
this might be useful:http://bit.ly/2Wgvtm
Post by Martin Trummer
what are you trying to do?
what is the form good for?
does it upload the image and afterwards you want to display this
uploaded image?
Post by zhangj5
Hi all,
I have a question about how to handle image/gif type response on
client side, any suggestion will be great.
There is a service which responds for retrieving image (only one each
time at the moment) from database. The code is something like,
JDBC Connection
Construct MYSQL query.
Execute query
If has ResultSet, retrieve first one {
image = rs.getBlob("img"); //save image into Blob image, “img” is the
only entity in the image table.
}
Then,
response.setContentType("image/gif"); //set response type
InputStream in = image.getBinaryStream();       //output Blob image to
InputStream
int bufferSize = 1024;  //buffer size
byte[] buffer = new byte[bufferSize];           //initial buffer
int length =0;
while ((length = in.read(buffer)) != -1) {//read length data from
inputstream and store into buffer
        out.write(buffer, 0, length);           //write into
ServletOutputStream}
in.close();
out.flush();            //write out
The code on client side
....
imgform.setAction(GWT.getModuleBaseURL() + "serviceexample/
ImgRetrieve");
....
ClickListener {
OnClick, then imgform.submit();
}
formHandler {
        onSubmit, form validation
        onSubmitComplete
            ??????? //handle response, and display image
        Here is my question, i had tried
        Image img = new Image(GWT.getHostPageBaseURL()
+"serviceexample/ImgRetrieve");
        mg.setSize("300", "300");
        imgpanel.add(img);
        but i only got a non-displayed image with 300X300 size.
}
So, how should i handle the responde in this case?
Thanks,
--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to google-web-toolkit+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=.
Loading...