views:

28

answers:

1

Hello, first timer here!

I've recently adopted the GWT framework and I've run into trouble. I'm creating a simple web-app which provides an input textarea and a list where the written articles are listed, a guestbook application if you will.

Now the problem is that I can't figure out how to maintain the list in a servletContext() - a global list. I can store data in a single session, but that wont do any good, since the point is that users have to look at the same list, not an individual one.

With Java servlets I'm used to storing objects in the ServletContext() which is globally available, but for the love of me I can't figure out how to do this with GWT.

Does anyone know how I can achieve this?

Thank alot!

A: 

Pretty straightforward -

  1. Write a GWT RPC service as explained here - http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunication.html
  2. The class that you write is just a normal java servlet. So you can invoke do the following to get the ServletContext

    ServletContext servletContext = getServletContext();

Having said that, you are better off storing the data to a database. ServletContext will not persist the data, it will be lost the moment you restart your server.

sri
Thanks, works like a charm.
Roberto