title: Accessing javascript variable in jsp in java
body: <p>I have included my javascript file in head of jsp file! What i want that there is a variable which is increasing everyone using click on the map, and i want that value in the jsp page. Please tell me how to do that, here is my code!</p>
  
  <p>The JSP file code! incremental value i is defined is ClickHandler.js</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;script src="http://www.openlayers.org/api/OpenLayers.js"&gt;&lt;/script&gt;
  &lt;script src="ClickHandler.js" type="text/javascript"&gt;
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;h1&gt;This is login Page&lt;/h1&gt;
  
  &lt;body onload='init();'&gt;
  
  
  &lt;form action="helloWelcome" method="post"&gt;
  &lt;input type="text" name="username"&gt;
  &lt;input type="text" name="surname"&gt;
  &lt;input type="submit" value="submit"&gt;
  &lt;div id="Map" style="height: 650px" &gt;&lt;/div&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is my ClickHandler.js file code!</p>
  
  <pre><code>var i=0;
  
  var map,vectorLayer, selectedFeature;
             var lat=33.7167;
              var lon=73.0667;
              var zoom=10;
              var map;
          var curpos = new Array();
          var position;
  
              var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
              var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
  
              var cntrposition       = new OpenLayers.LonLat(lon, lat).transform( fromProjection, toProjection);
  
          function init()
          {
                  map = new OpenLayers.Map("Map",{
                              controls: 
                              [
                                          new OpenLayers.Control.PanZoomBar(),                        
                              new OpenLayers.Control.LayerSwitcher({}),
                              new OpenLayers.Control.Permalink(),
                              new OpenLayers.Control.MousePosition({}),
                              new OpenLayers.Control.ScaleLine(),
                              new OpenLayers.Control.OverviewMap(),
                                      ]
                                }
                                  );
                  var mapnik      = new OpenLayers.Layer.OSM("MAP"); 
  
              map.addLayers([mapnik]);
              //map.addLayer(mapnik);
              map.setCenter(cntrposition, zoom);
  
              //markers.addMarker(new OpenLayers.Marker(cntrposition));
  
              var click = new OpenLayers.Control.Click();
              map.addControl(click);
  
              click.activate();
  };
  
  OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {               
   defaultHandlerOptions: {
    'single': true,
    'double': false,
    'pixelTolerance': 0,
    'stopSingle': false,
    'stopDouble': false
   },
  
   initialize: function(options) {
    this.handlerOptions = OpenLayers.Util.extend(
     {}, this.defaultHandlerOptions
    );
    OpenLayers.Control.prototype.initialize.apply(
     this, arguments
    );
    this.handler = new OpenLayers.Handler.Click(
     this, {
      'click': this.trigger
     }, this.handlerOptions
    );
   },
  
   trigger: function(e) {
    var lonlat = map.getLonLatFromPixel(e.xy);
    lonlat1= new OpenLayers.LonLat(lonlat.lon,lonlat.lat).transform(toProjection,fromProjection);
    var long_value=lonlat1.lon;
    var lat_value=lonlat1.lat;
    //action=""
    i=i+1;
    alert("ur coordinates ..."+i+" "+long_value + "  " +lat_value);
  
    //&lt;a href="login.jsp"&gt;&lt;a&gt;
    //&lt;link href="login.jsp" &gt;
   }
  });
  </code></pre>