我已将javascript文件包含在jsp文件的头部!我想要的是有一个变量,它增加了每个人使用点击地图,我想在jsp页面中的那个值。请告诉我怎么做,这是我的代码!
JSP文件代码!增量值i定义为ClickHandler.js
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
<script src="ClickHandler.js" type="text/javascript">
</script>
</head>
<h1>This is login Page</h1>
<body onload='init();'>
<form action="helloWelcome" method="post">
<input type="text" name="username">
<input type="text" name="surname">
<input type="submit" value="submit">
<div id="Map" style="height: 650px" ></div>
</form>
</body>
</html>
这是我的ClickHandler.js文件代码!
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);
//<a href="login.jsp"><a>
//<link href="login.jsp" >
}
});