var LonLat = function() {
var longitute;
var latitude;
return {
getLon: function() {
return this.longitute;
},
setLon: function(newLongitute) {
this.longitute = newLongitute;
},
getLat: function() {
return this.latitude;
},
setLat: function(newLatitude) {
this.latitude = newLatitude
}
};
};
var LonLat2 = function(longitute, latitude) {
var longitute;
var latitude;
return {
getLon: function() {
this.longitute = longitute;
return this.longitute;
},
getLat: function() {
this.latitude = latitude;
return this.latitude;
}
};
};
function Person(name, age) {
this.name = name;
this.age = age;
this.setName = function (newName){
this.name = newName;
};
this.getName = function() {
return this.name;
};
this.setAge = function(newAge) {
this.age = newAge;
};
this.getAge = function() {
return age;
};
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'JsObject.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="js/JsObject.js"></script>
<script type="text/javascript">
/*
var lonlat = new LonLat();
lonlat.setLon(50);
lonlat.setLat(80);
alert(lonlat.getLon() + ", " + lonlat.getLat() + ", "+ lonlat.longitute);
lonlat = new LonLat2(10, 79);
alert(lonlat.getLon() + ", " + lonlat.getLat() + ", "+ lonlat.longitute);
*/
var lonlat = new LonLat2(10, 30);
alert(lonlat.getLon() + ", " + lonlat.getLat() + ", " + lonlat.longitute + ", " + lonlat.latitude);
/*
var personList = [];
var person1 = new Person('jim', 20);
var person2 = new Person('jam', 21);
var person3 = new Person('linda', 22);
personList.push(person1);
personList.push(person2);
personList.push(person3);
for (var person in personList) {
alert(personList[person].getName() + "," + personList[person].getAge());
}
*/
</script>
</head>
<body>
This is my JSP page. <br>
</body>
</html>