RE: Sharing an object between servlets
Can't you use a session/request scope object? However it's not clear to me why you need to share the variables between the servlets without having them communicate directly. Hamish -Original Message- From: Vijay Kandy [mailto:[EMAIL PROTECTED]] Sent: Friday, October 04, 2002 4:28 PM 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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Sharing an object between servlets
Hi, There are many ways you can do this. Here are two examples: 1. Since the HTML servlet embeds the URL of the PNG servlet, why not put the coordinates in the URL? E.g. have the HTML servlet output img src=myPngServlet?x1=0x2=1 and then the PNG servlet does String x1 = request.getParameter(x1); and so forth. 2. Do you really go to the DB for each request? It may be better (at least for performance, but also addressing this sharing thing) to have a singleton responsible for getting coordinates from the DB. The servlets ask the singleton for the coordinates, which gets them. If the singleton doesn't have them, it goes to the DB and caches the results. So that the second time those coordinates are requested, it's a simple and quick hash lookup (or whatever kind of lookup suits you) to get them. This way you can also pre-cache frequently requested coordinates, and do all sorts of stuff to improve performance... But more importantly it keeps a nicer degree of decoupling between the two servlets. I hope this helps, Yoav Shapira Millennium ChemInformatics -Original Message- From: Vijay Kandy [mailto:[EMAIL PROTECTED]] Sent: Friday, October 04, 2002 10: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: mailto:tomcat-user- [EMAIL PROTECTED] For additional commands, e-mail: mailto:tomcat-user- [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Sharing an object between servlets
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:[EMAIL PROTECTED]] 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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Sharing an object between servlets
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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Sharing an object between servlets
The number of coordinates is huge - in thousands so cant put them in the URL. I have attempted your second idea. And yes I go to the DB for each request. The problem with the Singleton is, I donno who should start the class. If the HTML servlet starts the Singleton, will the object still be accessible to the image servlet? Thank you, -Vijay -Original Message- From: Shapira, Yoav [mailto:[EMAIL PROTECTED]] Sent: Friday, October 04, 2002 9:42 AM To: Tomcat Users List Subject:RE: Sharing an object between servlets File: ATT196478.txt File: ATT196479.txt Hi, There are many ways you can do this. Here are two examples: 1. Since the HTML servlet embeds the URL of the PNG servlet, why not put the coordinates in the URL? E.g. have the HTML servlet output img src=myPngServlet?x1=0x2=1 and then the PNG servlet does String x1 = request.getParameter(x1); and so forth. 2. Do you really go to the DB for each request? It may be better (at least for performance, but also addressing this sharing thing) to have a singleton responsible for getting coordinates from the DB. The servlets ask the singleton for the coordinates, which gets them. If the singleton doesn't have them, it goes to the DB and caches the results. So that the second time those coordinates are requested, it's a simple and quick hash lookup (or whatever kind of lookup suits you) to get them. This way you can also pre-cache frequently requested coordinates, and do all sorts of stuff to improve performance... But more importantly it keeps a nicer degree of decoupling between the two servlets. I hope this helps, Yoav Shapira Millennium ChemInformatics -Original Message- From: Vijay Kandy [mailto:[EMAIL PROTECTED]] Sent: Friday, October 04, 2002 10: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: mailto:tomcat-user- [EMAIL PROTECTED] For additional commands, e-mail: mailto:tomcat-user- [EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Sharing an object between servlets
Hmmm. I see what you are saying. But how does the HTML servlet write out the image map data? Thank you. -Vijay -Original Message- From: Sexton, George [mailto:[EMAIL PROTECTED]] Sent: Friday, October 04, 2002 9:48 AM To: Tomcat Users List Subject:RE: Sharing an object between servlets 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:[EMAIL PROTECTED]] 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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Sharing an object between servlets
Hi, The number of coordinates is huge - in thousands so cant put them in the URL. OK. Makes sense ;) I have attempted your second idea. And yes I go to the DB for each request. The problem with the Singleton is, I donno who should start the class. If the HTML servlet starts the Singleton, will the object still be accessible to the image servlet? They both call MapSingleton.getInstance(). It starts itself, as the constructor is private in the Singleton pattern. It may also suit you to start it in a context listener on server startup, and pre-populate what you need in the singleton. Yoav Shapira Millennium ChemInformatics This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Sharing an object between servlets
I've built something similar to this in the past. In my case, I was using a popular enterprise mapping API to generate the maps with points of interest (easy to guess which one). I stored long/lat of a user's recent published locations in the database. IE, the user has some kind of mobile device which publishes it's long/lat periodically. a web page then displays a map with a series of points. To get the time when the user published the point, image map is used. the image map is generated with the same long/lat in the database, but transformed from long/lat to pixel coordinates. I used several approaches, including sticking it in the session, but that got really slow with a couple simultaneous requests. Worked great for one person, but not under load. Your best bet is to either use a single as suggested by others, or write a webapp which starts with tomcat. This way it gives you more flexibility. If your building a field force application like for a shipping company to track their trucks, the webapp solution might be better. If you're database is on serious hardware and can handle hundreds of simultaneous connections, it might be more scalable. Again, it all depends on how it will be used in production. peter Vijay Kandy wrote: The number of coordinates is huge - in thousands so cant put them in the URL. I have attempted your second idea. And yes I go to the DB for each request. The problem with the Singleton is, I donno who should start the class. If the HTML servlet starts the Singleton, will the object still be accessible to the image servlet? Thank you, -Vijay -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Sharing an object between servlets
Go to: http://www.mhsoftware.com/caldemo/servlet/login Once you are logged in, choose Edit | Resource Types and click on the right most icon by the word facility. This shows what I was speaking of. You might want to change the date to 09/13/2002 and click on the Go button. The ViewGantt servlet generates the HTML, and the PNG image. It saves the PNG image on the user session. The graphic servlet just retrieves the image from the session. It sets the mime type to image/png and sends it to the client. 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:[EMAIL PROTECTED]] Sent: 04 October, 2002 9:17 AM To: 'Tomcat Users List' Subject: RE: Sharing an object between servlets Hmmm. I see what you are saying. But how does the HTML servlet write out the image map data? Thank you. -Vijay -Original Message- From: Sexton, George [mailto:[EMAIL PROTECTED]] Sent: Friday, October 04, 2002 9:48 AM To: Tomcat Users List Subject:RE: Sharing an object between servlets 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:[EMAIL PROTECTED]] 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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Sharing an object between servlets
I think I have an idea now. Thank you Sexton, Lin and Shapira! -Vijay -Original Message- From: Sexton, George [mailto:[EMAIL PROTECTED]] Sent: Friday, October 04, 2002 10:26 AM To: Tomcat Users List Subject:RE: Sharing an object between servlets Go to: http://www.mhsoftware.com/caldemo/servlet/login Once you are logged in, choose Edit | Resource Types and click on the right most icon by the word facility. This shows what I was speaking of. You might want to change the date to 09/13/2002 and click on the Go button. The ViewGantt servlet generates the HTML, and the PNG image. It saves the PNG image on the user session. The graphic servlet just retrieves the image from the session. It sets the mime type to image/png and sends it to the client. 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:[EMAIL PROTECTED]] Sent: 04 October, 2002 9:17 AM To: 'Tomcat Users List' Subject: RE: Sharing an object between servlets Hmmm. I see what you are saying. But how does the HTML servlet write out the image map data? Thank you. -Vijay -Original Message- From: Sexton, George [mailto:[EMAIL PROTECTED]] Sent: Friday, October 04, 2002 9:48 AM To: Tomcat Users List Subject:RE: Sharing an object between servlets 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:[EMAIL PROTECTED]] 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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]