Friday, August 26, 2011

Re: GWT + HttpServlets

Hi Karim Duran

I don't know any thing about GWT servlet.
Could you please provide me an elaborated example for the same, and where can I get the plugins for it.

On Thu, Aug 25, 2011 at 10:46 PM, karim duran <karim.duran@gmail.com> wrote:
Hi Hareen,

Could you be more precise. I don't understand what you mean !!!!

What do you want to do, generate dynamically an image with a servlet ?
What kind of servlet ? a J2EE standard servlet or a GWT servlet ?

So, imagine that in your WebApp, your user is logged and you have store userID in session as a String.
Imagine you use doGet(HttpServletRequest req, HttpServletResponse resp) servlet method (GET HTTP action)

1) to retrieve information in session in standard J2EE servlet class just do that :
String userID = (String)req.getSession().getAttribute("userID"); // return the userID already stored in session

So, imagine that you get imageID as a request parameter named imageid
2) to serve an image from your servlet just do that :
String imageID = req.getParameter("imageid"); // retrieve the request parameter imageid
resp.setContentType("image/png"); // you want to serve a PNG image

3) proceed to serve the image in HTTP outputstream
.../.. get image data in byte array byte[] imageBytes .../...
ServletOutputStream out = resp.getOutputStream();
out.write(imageBytes);
out.close();

4) Register your servlet "getimage" in web.xml in order the J2EE container knows it exists

5) call your servlet with a url link in your web page :
/getimage?imageid=123456

That's all.

If you send me more information about what you want to do, i can help you more.
GWT servlet extends standard HttpServlet, so methods are still available.

I hope it helps.

Regards.
Karim Duran



2011/8/25 Hareen Bejjanki <bejjanki.hareen@gmail.com>
Can any one please suggest me a way to link an image to a HttpServlet,
where I can use sessions, requests and etc..................

--
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@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


--
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@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.



--
Thanks & Regards
Hareen Bejjanki

--
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@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment