js中的数值 对象

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.deng.testjs.model.Person"%>
<%
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 'index.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">
	  function my(){
	    var list = <%= getValue() %>
	    alert(list[0].address);
	    
	    //对象可以直接写,包括方法
	    var object = {name:"shangsan",age:20};
	    alert("object age=" + object.age);
	    
	    //数组
	    var array = ["a","b","c"];
	    alert("array test = " + array[1]);
	  }
	
	</script>
	
  </head>
  
  
  <body>
  <%!
public String getValue() throws Exception {
  List<Person> list = new ArrayList<Person>();
  Person p1 = new Person();
  p1.setName("zhangsan");
  p1.setAddress("a1");
  list.add(p1);

  Person p2 = new Person();
  p2.setName("lisi");
  p2.setAddress("a2");
  list.add(p2);
  
  StringBuffer sb=new StringBuffer();
  for(Person p:list){
   sb.append("");
  }
  
  return "[{name:'a',address:'b'}]";
}
%>
    This is my JSP page. <br>
    <input type="button" onclick="my()" value="test">
  </body>
</html>
 

你可能感兴趣的:(js)