简体   繁体   English

从Web应用程序向服务器发送位置更新

[英]send location updates to server from web app

I have written a web app with a few JSP pages and Java servlets running on a Tomcat server. 我编写了一个Web应用程序,其中包含一些在Tomcat服务器上运行的JSP页面和Java servlet。 The app needs to be able to send location updates to one of the Servlets every x seconds. 该应用需要能够每x秒将位置更新发送到其中一个Servlet。 I have found the html5 watchPosition(sucess_callback, error_callback) function to get the location updates from the web page. 我已经找到了html5 watchPosition(sucess_callback,error_callback)函数来从网页获取位置更新。 I'm thinking.. once I get the update from this function.. I'll put code in the callback function to send the update to a Servlet. 我在想..一旦从此函数获得更新..我会将代码放入回调函数中,以将更新发送到Servlet。 But adding the watchPosition function to every JSP page in the app seems cumbersome. 但是向应用程序中的每个JSP页面添加watchPosition函数似乎很麻烦。 What is the right way to send periodic GPS updates to the server no matter whatever webpage the user is viewing in the app? 不管用户在应用程序中正在浏览哪个网页,将定期GPS更新发送到服务器的正确方法是什么?

I'm not sure whether you can create any code which continues to send location data when the user loads another web-page. 我不确定您是否可以创建任何代码来在用户加载另一个网页时继续发送位置数据。 The web is a stateless thing and when the user opens another page other code is executed. Web是无状态的,当用户打开另一个页面时,将执行其他代码。 I suspect that the JSP is the codebase from which HTML is produced when sent to the mobile-phone. 我怀疑JSP是发送到手机时从中生成HTML的代码库。 My idea would be to add the location sending functionality as AJAX requests in the Javascript. 我的想法是在Javascript中添加位置发送功能作为AJAX请求。 If your web-app is based on many links between pages and full loads it could also be an idea to implement Ajax for loading new content into the page. 如果您的Web应用基于页面和完整负载之间的许多链接,那么实现Ajax将新内容加载到页面中也是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM