jsp文档中的谷歌地图
我正在尝试将 google 地图 api 实现到我的由 jsp 文档生成的网页之一中,但我无法使其正常工作。我通过 www.lamatek.com/GoogleMaps 找到了一些 jsp taglibrary,但它似乎不起作用。(我的意思是,即使他们网站上的示例也不起作用)
有人在 jsp 文档中做过谷歌地图的工作吗?我确实可以使用一些帮助或建议。(似乎 jsp docuemnt 和 javascript 不能相处)
ps 我可以获得静态谷歌地图工作,但这不是我的客户想要的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这确实不是JSP 问题。问题出在其他地方。也许这只是你自己对JSP的无知。你需要认识到,JSP 只不过是一种服务器端视图技术,它提供了一个用于编写 HTML/CSS/JS 的模板。以通常的方式编写“plain vanila”HTML/CSS/JS 是完全可以的。一个 JSP 文件。除非您想要动态控制页面流或输出,或者想要用单个小标签替换重复/重复的代码块,否则不需要标签库。可以使用表达式语言访问后端数据。
如果你的实际问题是 JSP 和 JS 之间的“通信”,那么你需要再次认识到 Java/JSP 基本上运行在服务器机器,只生成一个 HTML 页面(里面有 CSS/JS)并将其发送到客户端。反过来,JS 仅在客户端计算机上运行,看不到 JSP 中的任何内容。您可以使用 JSP 动态生成 JS 函数/变量。您可以使用 JS 向服务器端发出同步 HTTP 请求,服务器端又可以执行一些 Java 代码。要获得更多见解和示例,您可能会发现这篇文章很有用。
首先,只需将该静态
.html
文件重命名为动态.jsp 文件,它仍然可以工作;)您不需要特定的标记库。如果你想动态输出/渲染 HTML/CSS/JS,请使用流控制标签,如 JSTL core。如果你想动态访问后端数据,请使用EL。
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.
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.
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.我设法让 lamatek 标签库正常工作,但有一个错误我必须先修复,您可以下载源代码,修复错误(见下文)并创建 googlemaps.jar 文件。
谷歌地图团队似乎已经更改了地图类型常量:
旧/新
G_HYBRID_TYPE / G_HYBRID_MAP
G_SATELLITE_TYPE / G_SATELLITE_MAP
G_MAP_TYPE / G_NORMAL_MAP
在文件 com/lamatek/tags/google/GoogleMapTag.java 中更改第 928、931 和 934 行,替换上述常量。
应该这样做!
根据请求,这里是 jar 文件.(使用 JDK 1.6 构建)
/Björn Darri
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.
That should do it!
As per request, here is the jar file. (built with JDK 1.6)
/Björn Darri