esp*_*fee 5 coldfusion session session-management coldfusion-2016
我有查询应该在会话结束时运行.如果有记录与用户帐户绑定,那么我想删除该记录.我使用会话范围来存储用户ID.用户手动注销或会话超时后,应运行此查询.这是一个例子:
public void function onSessionEnd(required struct sessionScope, struct applicationScope={}) {
local.qryTest = new Query();
local.qryTest.setDatasource("#arguments.Application.dsnWriteDelete#");
local.qryTest.setSQL("DELETE Locked WHERE RecID = :RecID");
local.qryTest.addParam(name="RecID",value="#SESSION.userID#",cfsqltype="cf_sql_integer");
qryTest.execute();
return;
}
Run Code Online (Sandbox Code Playgroud)
我在我的应用程序中使用J2EE会话.以下是用户手动注销时结束会话的方法:
<cffunction name="LogOut" access="remote" output="yes" returnformat="JSON">
<cfset local.fnResults = structNew()>
<cfif structKeyExists(SESSION.AccountInfo, "AccountID")>
<cftry>
<cfset local.temp = getPageContext().getSession().invalidate()>
<cfset local.fnResults = {status : "200"}>
<cfcatch type="any">
<cfset local.fnResults = {status : "400", message : "Error! Please contact your administrator."}>
</cfcatch>
</cftry>
<cfelse>
<cfset local.fnResults = {status : "400", message : "Error! Please contact your administrator."}>
</cfif>
<cfreturn fnResults>
</cffunction>
Run Code Online (Sandbox Code Playgroud)
我不确定onSessionEnd是否与J2EE有任何不同,但我上面的代码从不删除数据库表中的记录.我不确定我的代码中是否有问题,或者在会话结束时无法实现.
该范围在OnSessionEnd()session内不可用。您必须改用参数名称,即arguments.sessionScope
但是,如果用户手动注销,则不会触发 onSessionEnd。您知道是否可以手动触发 onSessionEnd int [t]hat 案例?
从技术上讲是可以的,尽管将注销逻辑放置在组件中然后从两个位置(OnSessionEnd 和手动注销脚本)调用适当的方法可能更有意义。
| 归档时间: |
|
| 查看次数: |
98 次 |
| 最近记录: |