You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Vijay Kandy <Vi...@mailcode.com> on 2002/10/04 16:28:14 UTC

Sharing an object between servlets

Dear All,

We are building a map tool - to draw maps and show some data on them. Now, I
have this situation. I have a servlet that gets coordinates from the
database and draws the map on its OutputStream (the content type is set to
png image). There is another servlet (content type is text/html) that embeds
the URL of the first servlet. This servlet also gets coordinates from the
database, and populates them over the image so I can do some image map or
mouseOver() tricks using javascript. I was wondering if there was a way to
make just one call to the database and share the coordinates between the
servlets. Right now, I will try any thing!

Thank you,
Vijay
 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Sharing an object between servlets

Posted by peter lin <pe...@labs.gte.com>.
Sounds like you want some kind of persistent storage that cross multiple
requests. If I am reading you correctly, rather than have one servlet do
both the html and png, you've split the functionality into two servlets.

Assuming you're using tomcat 4, you should be able to create a
light-weight application that uses a map. I can think of a couple
different ways to tackle the problem.

1. store the lat/long in the session. One down side of this is it may
bog down the session object if your object increases in size

2. create an application wide map that stores an object containing the
geocode (lat/long), using session as the key

3. store in a database using the session id as key

4. store it in some other persistent datastore

5. pass the lat/long in the URL the map generation servlet creates for
the html servlet

I'm not sure how you're generating the map url, since it sounds like the
map servlet handles that. I'm assuming the map servlet takes an address
or an equivalent to generate the graphic. You might want to provide more
specific information like the process flow to get better help.

peter


Vijay Kandy wrote:
> 
> Dear All,
> 
> We are building a map tool - to draw maps and show some data on them. Now, I
> have this situation. I have a servlet that gets coordinates from the
> database and draws the map on its OutputStream (the content type is set to
> png image). There is another servlet (content type is text/html) that embeds
> the URL of the first servlet. This servlet also gets coordinates from the
> database, and populates them over the image so I can do some image map or
> mouseOver() tricks using javascript. I was wondering if there was a way to
> make just one call to the database and share the coordinates between the
> servlets. Right now, I will try any thing!
> 
> Thank you,
> Vijay
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Sharing an object between servlets

Posted by "Sexton, George" <gs...@mhsoftware.com>.
I have done what you are attempting. The problem with decoupling as
suggested by others is that you end up duplicating the logic to create the
image, and the image map.

My solution was to have the servlet generate the graphic and save it on the
session. The HTML servlet wrote out an image tag to another servlet that did
nothing but retrieve the generated session from the image.

Perhaps a more scalable approach would be to write the image out as a file,
and have a servlet that reads the file. A reference could be saved on the
session.

George Sexton
MH Software, Inc.
Home of Connect Daily Web Calendar Software
http://www.mhsoftware.com/connectdaily.htm
Voice: 303 438 9585


-----Original Message-----
From: Vijay Kandy [mailto:VijayK@mailcode.com]
Sent: 04 October, 2002 8:28 AM
To: 'Tomcat Users List'
Subject: Sharing an object between servlets



Dear All,

We are building a map tool - to draw maps and show some data on them. Now, I
have this situation. I have a servlet that gets coordinates from the
database and draws the map on its OutputStream (the content type is set to
png image). There is another servlet (content type is text/html) that embeds
the URL of the first servlet. This servlet also gets coordinates from the
database, and populates them over the image so I can do some image map or
mouseOver() tricks using javascript. I was wondering if there was a way to
make just one call to the database and share the coordinates between the
servlets. Right now, I will try any thing!

Thank you,
Vijay


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>