我正在访问Jsp中的会话变量,然后在Jquery中访问同一个变量,但每当会话在mvc控制器上更新时,它就不会在Jsp视图中更新。
例如: -
<c:if test="${!empty session.accounts}">
<div>
<span> All Accounts: </span>
</div>
<ul id="accountList" class="ui-menu ui-widget ui-widget-content"
role="menu" tabindex="0" style="width: auto;">
<c:forEach items="${session.accounts}" var="account">
<li><i class="ace-icon glyphicon glyphicon-user blue"></i>
<span class="green">${account.name}</span> <c:if
test="${fn:length(session.accounts) gt 1}">
<a class="red" data-toggle="modal" href="#modal-delete-confirm"
data-id="${account.id }" data-type="${session.type }"
data-handle="${account.handle }"> <i
class="ace-icon fa fa-trash-o bigger-120 orange pull-right"
title="Remove Account"></i>
</a>
</c:if></li>
</c:forEach>
</ul>
</c:if>
然后我点击删除用户帐户并点击是时显示模态窗口。我正在mvc控制器发送ajax请求。
$('#btnYes').click(
function() {
$('#modal-delete-confirm').modal('hide');
// handle deletion here
var socialAccountId = $('#modal-delete-confirm').data(
'socialAccountId');
var type = $('#modal-delete-confirm').data('type');
$('[data-socialAccountId=' + socialAccountId + ']').remove();
$.ajax({
url : contextPath + '/removeAccount',
data : {
'socialAccountId' : socialAccountId
},
type : "POST",
success : function() {
switchAccountView();
},
});
});
从帐户列表中删除我在MVC控制器的会话对象中维护的帐户。
@RequestMapping(value = "/removeAccount", method = RequestMethod.POST)
public @ResponseBody void removeSocialAccount(
@RequestParam("socialAccountId") String socialAccountId,
@ModelAttribute("session") SessionWrapper session) {
if (Utils.isNotEmpty(socialAccountId)) {
for (SocialAccount account : session.getAccounts()) {
if (account.getId().equals(socialAccountId)) {
try {
GenericResponse response = ApiManager.getInstance()
.removeSocialAccount(socialAccountId,
session.getAccount());
if (response.getResponseCode() == ResponseCode.SUCCESS
.getValue().intValue()) {
session.getAccounts().remove(account);
if (socialAccountId.equals(session
.getCurrentAccount().getId())) {
session.setCurrentAccount(session.getAccounts()
.get(0));
}
session.setSuccess("Account removed successfully");
}
} catch (Exception e) {
logger.error(e.getMessage());
session.setError(e.getMessage());
}
}
}
}
}
但是现在这个会话变量没有在JSP视图中更新。帮助我摆脱这个问题,因为我是编程的新手,并且善意地忽略了糟糕的英语。