且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在jsp文档中使用Google地图

更新时间:2023-01-16 17:14:32

这实际上不是JSP问题。问题在于别的地方。也许这只是你自己对JSP的无知。您需要认识到,JSP是一种服务器端视图技术,它提供了一个用于编写HTML / CSS / JS的模板。您可以使用通常的方式编写plain vanilaHTML / CSS / JS一个JSP文件。除非您想要动态控制页面流或输出,或者希望用一个小标签替换重复/重复的代码块,否则不需要使用Taglib。后端数据可以使用表达式语言来访问。


(看起来像jsp docuemnt和javascript只是不相处)这篇文章有用。


ps我可以获得静态Google地图工作,但这不是我的客户想要的。


首先,将该静态 .html 文件重命名为动态 .jsp 文件,它仍然可以工作;)你不需要特定的taglibs。如果您想动态输出/呈现HTML / CSS / JS,请使用JSTL内核等流量控制标记。如果您想要动态访问后端数据,请使用EL。


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.

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.