【问题标题】:How to pass geolocation values to variable and to sql query in jsp如何将地理位置值传递给变量和jsp中的sql查询
【发布时间】:2016-10-20 05:54:57
【问题描述】:

以下代码,我用于在 jsp/javascript/html 中获取 GeoLocation。

<script>
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function (position) {
        alert(position.coords.latitude + ", " + position.coords.longitude);
        });

    }

</script>

现在,我需要将这些值存储在数据库中,该查询位于 jsp 标记中。 我们怎样才能用一个变量存储这个纬度、经度值,然后传递给查询。

【问题讨论】:

标签: javascript java html jsp geolocation


【解决方案1】:

选项 1:-

如果您要在 jsp 中提交任何表单,请输入如下所示的隐藏值

<input type="hidden" id="geoLocation" >

然后在页面开始加载时设置此项,即在windows.onLoad 中或在加载空页面后,即在 jQuery $document.ready{}

设置值为

if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function (position) {
      document.getElementById("geoLocation").value=position.coords.latitude + ", " + position.coords.longitude;
        }
      );
}

然后用表单提交...

选项 2:-

尝试使用AJAX DWR 组件,它可以让您使用单个 DAO 类(即简单的 POJO 类)将数据添加到数据库中

其官方网站上列出了所有步骤:- http://directwebremoting.org/dwr/introduction/getting-started.html

如果您使用 MVC,您将需要在您的 jsp 中包含 2 个 javascript 文件并授予 DWR 访问您的 DAO 方法的权限,但在这种情况下,我更喜欢为 DWR 制作单独的 DAO,您就完成了...

【讨论】:

    猜你喜欢
    • 2017-06-13
    • 1970-01-01
    • 2013-05-05
    • 2019-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-03
    相关资源
    最近更新 更多