Option 1:-
If you are going to submit any form in the jsp the put a hidden value like below
<input type="hidden" id="geoLocation" >
Then set this when page starts loading i.e. in windows.onLoad
or after loading the hole page i.e. in jQuery $document.ready{}
Set value as
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
document.getElementById("geoLocation").value=position.coords.latitude + ", " + position.coords.longitude;
}
);
}
And then submit it with the form...
Option 2 :-
Try to use AJAX DWR component which will let you add data to the data base with a single DAO class i.e. simple POJO class
All steps to do it are listed on its official website :- http://directwebremoting.org/dwr/introduction/getting-started.html
You will need to include 2 javascript file to your jsp and give DWR access to your DAO methods if you are using MVC but in this case i prefer to make seprate DAO just for DWR and you are Done...