tags:

views:

107

answers:

5

I have a JSP page that renders, and calls a Web service to load some initial data. The user fills out some form information, and then submits it to the server, which could possibly return the same JSP page for further processing (and another submit). The initial data never changes, but it is an object representation, so I'm trying to figure out how to maintain it between each POST so I'm not always calling the service. Is a session variable the only way to do this? Any help is appreciated. Thanks!

+4  A: 

I would stuff it in the session variable at login time - storing data in the client is intrinsicly insecure. If you do not expire your sessions but create them so they can be serialized to storage instead and use a web container supporting that, you never have to reload them.

If that is not interesting then create a cache around the web service so the results are kept there, and expired after some inactivity. That will require active cleaning up though.

Thorbjørn Ravn Andersen
+2  A: 

Session is the way to go. Do you really need to send it over the wire each time? Think of JSON if there is the real purpose, but otherwise use session and store it on server side.

Superfilin
+2  A: 

Depending on how the web service is set up, you could perhaps interpose a caching layer between you and it. For example, if it's a REST web service (or at least one that properly allows GET responses to be cached), then you can keep on fetching stuff from it, but nearly all your requests will get answered from your local HTTP cache.

If you decide on serialization, you can use XML, JSON, or another approach, eg Google's Protocol Buffers. With highly automated serialization libraries like XStream you can even automate the mappings for JavaBeans.

Jim Ferrans
+5  A: 
OscarRyz
+1: clear and to the point.
BalusC