Google map in jsp document

爱⌒轻易说出口 提交于 2019-12-13 05:36:53

问题


I am trying to implement google map api into one of my web page which is generated by jsp document, and I am having trouble getting it work. I found some jsp taglibrary by www.lamatek.com/GoogleMaps, but it doesn't seem to work.(I mean even examples on their web site don't work)

Has anyone done work on google map in jsp document? I can really use some help or advice.(It seems like jsp docuemnt and javascript just don't get along)

p.s I can get static google map work, but that's not my client wants.


回答1:


This is really not a JSP problem. The problem lies somewhere else. Maybe it is just your own ignorace of JSP. You need to realize that JSP is nothing less or more than a server-side view technology which provides a template to write HTML/CSS/JS in. It is perfectly fine to write "plain vanila" HTML/CSS/JS the usual way in a JSP file. Taglibs are not required unless you want to control the page flow or output dynamically, or want to replace duplicated/repeated code blocks by a single small tag. Backend data can be accessed using Expression Language.

(It seems like jsp docuemnt and javascript just don't get along)

If your actual problem is the "communication" between JSP and JS, then you need to realize once again that Java/JSP basically runs at the server machine, just produces a HTML page (with CSS/JS inside) and sends it to the client side. JS in turn, only runs at the client machine and doesn't see anything from JSP. You can use JSP to generate JS functions/variables dynamically. You can use JS to fire (a)synchronous HTTP requests to the server side which in turn can execute some Java code. To get more insights and examples you may find this article useful.

p.s I can get static google map work, but that's not my client wants.

To start, just rename that static .html file to a dynamic .jsp file and it will still work ;) You don't need specific taglibs for it. If you want to output/render HTML/CSS/JS dynamically, use flow control tags like JSTL core. If you want to access backend data dynamically, use EL.




回答2:


I managed to get the lamatek tag library to work but there was a bug I had to fix first, you can download the source, fix the bug (see below) and create the googlemaps.jar file.

The google maps team seem to have changed to map type constants:

old / new
G_HYBRID_TYPE / G_HYBRID_MAP
G_SATELLITE_TYPE / G_SATELLITE_MAP
G_MAP_TYPE / G_NORMAL_MAP

In the file com/lamatek/tags/google/GoogleMapTag.java change lines 928, 931 and 934 replacing the above mentioned constants.

//com.lamatek.tags.google.GoogleMapTag lines 927 - 935
if (type.equalsIgnoreCase("hybrid")) {
    out.println("\t\t" + id + ".setMapType(G_HYBRID_MAP);");
}
else if (type.equalsIgnoreCase("satellite")) {
    out.println("\t\t" + id + ".setMapType(G_SATELLITE_MAP);");
}
else {
    out.println("\t\t" + id + ".setMapType(G_NORMAL_MAP);");
}

That should do it!

As per request, here is the jar file. (built with JDK 1.6)

/Björn Darri



来源:https://stackoverflow.com/questions/2364504/google-map-in-jsp-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!