开发中遇到了难题,A页面和B页面进行数据交互,A页面把对象传递给B页面,并且A页面会异步刷新出B页面的内容。所以用到了$.load方法。B页面通过使用el表达式获取A页面的传递的参数,只能获取普通的参数,对于一些集合或者数组无法获取。希望有大神帮忙看看。
A页面js:
B页面获取参数:
想知道到底如何能遍历到group的集合元素呢,很费解网上也找不到什么方法。谢谢了
可以正常获取myParam的name属性,但是group获取不到。
<%@ 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 'MyJsp.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">
--> </head>
<body>
<button onclick="showDiv();">点击我</button>
<div id="showDiv"></div>
</body>
<script type="text/javascript" src="./js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function showDiv() {
var myParam = {
name: 'aaa',
group:[
{
myName:'a',
age:'16'
},
{
myName:'b',
age:'162'
}
]
};
$('#showDiv').load('./MyJsp.jsp', myParam,function(result) {
$('#showDiv').html(result);
});
}
</script>
</html><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.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">
--> </head>
<body>
<p>${param.name}</p>
<c:forEach items='${param.group}' var='group'>
<p>${group.myName}</p>
</c:forEach>
</body>
</html>
A页面js:
B页面获取参数:
想知道到底如何能遍历到group的集合元素呢,很费解网上也找不到什么方法。谢谢了
可以正常获取myParam的name属性,但是group获取不到。
<%@ 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 'MyJsp.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">
--> </head>
<body>
<button onclick="showDiv();">点击我</button>
<div id="showDiv"></div>
</body>
<script type="text/javascript" src="./js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function showDiv() {
var myParam = {
name: 'aaa',
group:[
{
myName:'a',
age:'16'
},
{
myName:'b',
age:'162'
}
]
};
$('#showDiv').load('./MyJsp.jsp', myParam,function(result) {
$('#showDiv').html(result);
});
}
</script>
</html><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.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">
--> </head>
<body>
<p>${param.name}</p>
<c:forEach items='${param.group}' var='group'>
<p>${group.myName}</p>
</c:forEach>
</body>
</html>
要传数组和对象时要转换成json格式的字符串
myParam.group = JSON.stringify(myParam.group);
服务器接收后也是要用相应的函数将json格式的字符串转换成服务器语言中的数组和对象
我希望能在el表达式直接获取到JSON格式的数据,这样我在操作遍历的时候就简洁很多了。
//console.log(query);
$('#loadteammember').load("<%=request.getContextPath() %>/memberManage/teammember",query); // ajax加载页面