这是我的示例html页面,其中包含内联javascript,它计算地理编码并尝试返回纬度和经度。但我的问题是如何将showlocation函数返回的纬度和经度的所有表单值提交到submitform.jsp页面并在jsp页面中显示纬度值。
的index.html
<html>
<head>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA5yM-fP6TPUheIXxW3TxpVRRgJAR_YXLeqIBw9Qs7Dzlh-4wFexRUVFiN8RbSageQjhAggT3jom"
type="text/javascript"></script>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
geocoder = new GClientGeocoder();
function showlocation() {
var clientaddress = document.getElementById('addstreetname').value;
geocoder.getLocations(clientaddress, function(response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode the first address");
}
else {
var lat1 = response.Placemark[0].Point.coordinates[1];
var lng1 = response.Placemark[0].Point.coordinates[0];
return {latitude: lat1, longitude: lng1};
}
});
</script>
</head>
<body>
<form id="addresslistingform" action="submitform.jsp" onsubmit="returnshowlocation();">
Company_Name:<br/>
<input size="30" type="text" id="businessname" name="businessname"/><br/>
Zipcode:<br/>
<input size="30" type="text" id="zipcode" name="zipcode1"/><br/>
Street No:<br/>
<input size="30" type="text" id="addstreetno" name="streetno"/><br/>
Street Name:<br/>
<input size="30" type="text" id="addstreetname" name="streetname"/><br/>
State:<br/>
<select name="select2" id="select2" class="required" name="state" >
<option value="">Select Your State</option>
<option value="1"> karnataka</option>
<option value="2"> Kerala</option>
<option value="3"> Andhra Pradesh</option>
</select>
</form>
</body>
</html>
submitform.jsp
<%@ page language="java" import="java.sql.*" %>
<%
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try{
String url = "jdbc:mysql://localhost:3306/";
String dbName = "db";
String driverName = "com.mysql.jdbc.Driver";
String userName = "";
String password = "";
con = DriverManager.getConnection(url+dbName, userName, password);
stmt=con.createStatement();
}catch(Exception e){
System.out.println(e.getMessage());
}
String Company_Name=request.getParameter("businessname");
String Zipcode =request.getParameter("zipcode1");
String Street_Number=request.getParameter("streetno");
String Street_Name=request.getParameter("streetname");
String State= request.getParameter("state");
String Latitude=request.getParameter("Latitude");
out.println("latitude is :"+request.getParameter("Latitude"));
%>
答案 0 :(得分:1)
单向直接将其附加到myJsp.jsp?lat=value&lon=value
GET
,
另一种方法是保留一个隐藏的参数,并在其中设置lat,lon和POST
。