开发者

how to pass form values from javascript to jsp page

开发者 https://www.devze.com 2023-01-24 07:08 出处:网络
This is my sample html page which contains inline javascript which calculates the geocode and tries to return the latitude and longitude .But my question is how to submit all the form values with lati

This is my sample html page which contains inline javascript which calculates the geocode and tries to return the latitude and longitude .But my question is how to submit all the form values with latitude and longitude returned from showlocation function to submitform.jsp page and display latitude value in jsp page .

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");开发者_如何学Python    
   String Latitude=request.getParameter("Latitude");
    out.println("latitude is :"+request.getParameter("Latitude"));

          %>


one way directly append it in url like myJsp.jsp?lat=value&lon=value GET,

another way is to keep a hidden param and set lat , lon in it and POST it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号