由於sessionScope
是服務器端對象,您必須使用SSJS代碼清除它。您無法直接從CSJS中清除它,但可以從CSJS中調用SSJS代碼。要從CSJS調用SSJS,您可以使用擴展庫中的JSON-RPC服務。
下面是一個例子:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
<xe:jsonRpcService id="jsonRpcService1" serviceName="myRpcService">
<xe:this.methods>
<xe:remoteMethod name="clearSessionScope">
<xe:this.script>
<![CDATA[
var iterator = sessionScope.keySet().iterator();
while(iterator.hasNext()){
sessionScope.remove(iterator.next());
}
return "sessionScope cleared";
]]>
</xe:this.script>
</xe:remoteMethod>
</xe:this.methods>
</xe:jsonRpcService>
<xp:button value="Clear sessionScope" id="button1">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script>
<![CDATA[
var deferred = myRpcService.clearSessionScope();
deferred.addCallback(function(result) {
alert(result);
});
]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>
</xp:view>
謝謝 - 我會給本週稍後再試。 –