1.前台从后台的数据获取。
var userId = ' <%= session.getAttribute("clientUserId")%> '
而session的设置是在ClientUserController里,
session.setAttribute("clientUserId",saved.getId());
2.前台从后台的数据获取。(接口形式)
var ctx = "${pageContext.request.contextPath}";
var buildingId = '<%=request.getParameter("buildingId")%>';
htmlobjWeibo = $.ajax({url: ctx + "/building/getBuilding?buildingId=" + buildingId, async: false});
appListWeibo = $.parseJSON(htmlobjWeibo.responseText).data;
contentWeibo = appListWeibo.description;
3. Jsp与Jsp之间参数传递。通过点击events.jsp中的链接进入house-detail.jsp,将house-detail.jsp所需要的参数传递。
$('#photo0').attr('href',ctx+"/house-detail.jsp?activityId="+appList[0].activityId);
house-detail.jsp中接收从events.jsp中传来的参数。
var buildingId = '<%=request.getParameter("buildingId")%>';
4.Jsp向后抬传递数据。
$.ajax({
//提交数据的类型 POST GET
type: "POST",
//提交的网址
url: ctx + "/comment/createComment",
//提交的数据
data: {
clientUserId: appList.clientUserId,
buildingId: appListActivity.buildingId,
content: $("#content").val()
},
//返回数据的格式
datatype: "json",
//成功返回之后调用的函数
success: function (data) {
alert2("评论成功,获取1积分!请刷新页面确认");
htmlobjIntegral = $.ajax({url: ctx + "/anonymous/addIntegralByUserId?clientUserId=" + userId, async: false});
var appListIntegral = $.parseJSON(htmlobjIntegral.responseText).data;
},
//调用出错执行的函数
error: function () {
//请求出错处理
}
});