aspose file tools*
The moose likes JSP and the fly likes How to show data from database by onmouseover image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to show data from database by onmouseover image" Watch "How to show data from database by onmouseover image" New topic
Author

How to show data from database by onmouseover image

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Hi.
I have got a JSP page, which has a map. On this map there are various cities. I want to display data related to any city, selected by moving cursor over it on the map, picked from database.
How do I do this? Please suggest.
Thanks,
Abhishek
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42936
    
  68
This has nothing to do with JSP, but HTML. You need an imagemap that has entries for your points of interest. That imagemap can (on mouseover) trigger any kind of JavaScript action, e.g. changing a div tag that contains the city data, or displaying some kind of tooltip.
Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
Hi Ulf,
That I know, that we can trigger any action using onmouseover, but the problem here is that we have to get the data from database, which will be done by JSP scriptlet only.
Can I call any JSP scriptlet using onmouseover?
Please tell this.
Abhishek
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Can I call any JSP scriptlet using onmouseover?


No. Once the page has been sent to the browser any opportunity to execute Java code is gone. In order to execute server-side code you must submit back to the server.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Here's one possible way of doing this:

Create a table for each possible city with all the information populated in your jsp. Give each table an id="??name of city??" attribute, and a style="visibilty:hidden;display:none". That way each city's information is in the html document when it is sent to the browser, but none of it is visible on the page. Then you can program the mouseover event of javascript to display the information for a specific city by having it find the appropriate table and changing it's style.visibility and style.display attributes.

The above will work well if there are only a few cities to be displayed, but if there are many, you will want to look for a different solution, as the page will be very large and take a long time to load.

The important thing to remember is that JSP tags can only affect information that is put in the html document before it is rendered into html and sent to the browser. Once the html document is rendered and sitting in the browser, all the information you need has to be there, and the only way of manipulating it is through javascript.


Merrill
Consultant, Sima Solutions
Niki Nono
Ranch Hand

Joined: Mar 20, 2005
Posts: 256
You can try Using Ajax.
check out this site www.maps.google.com and i think you need something similar.
Search for ajax in the html/javascript forum. plenty has been discussed.
Although as ulf has suggested you need to use image maps to get the mouseover city name.
[ August 05, 2005: Message edited by: Niki Nono ]

Life called,so here I am.<br />Cheers<br />Niki.:-)
Dan Novik
Ranch Hand

Joined: Jan 26, 2005
Posts: 39
yes, it is what Ajax is for.
You can call server side stuff right from JavaScript
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42936
    
  68
With all due respect, this is not a good application for AJAX. Unless we're talking about thousands of cities (or KiloBytes of data per city), it's better to embed the data in the page, either in JavaScript or in invisible elements, much like Merrill suggests. It will be much more responsive that way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to show data from database by onmouseover image