Hi
i have problems with sessions variables with safari after upgrade to version 4.
it seems that browser lose values.
Chrome and firefox works correctly.
In safari i have the accept cookies and data from all sites active.
can anyone help me?
Sub Class_Globals
End Sub
Public Sub Initialize
End Sub
Sub Handle(req As ServletRequest, resp As ServletResponse)
Dim i As Int = req.GetSession.GetAttribute2("i", 0)
req.GetSession.SetAttribute("i", i + 1)
resp.Write(i)
End Sub
The number is incremented. Do you see a different behavior?
Sub LocalStorage_SetItem(Key As String, Value As Object)
mWS.Eval("$.jStorage.set(arguments[0], arguments[1]);", Array As Object(Key, Value))
End Sub
B4X:
Sub LocalStorage_GetItem(Key As String, Default As Object) As Future
Return mWS.EvalWithResult("return $.jStorage.get(arguments[0], arguments[1]);", Array As Object(Key, Default))
End Sub
i have a strangeness the jstorage.js must be lowercase.
Yes, that is the one I suspected it could go wrong. I think it happens when you move to another 'page' on your website. Pre 4.0 could do this, but 4.0 has some troubles saving the session vars. Unfortunately, ABMaterial relies a lot on this technique.
Local storage was indeed also my alternative solution. Maybe it is the new jetty version that plays a role in it?
'Return True to allow the request to proceed.
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
req.GetSession 'a new session will be created if a session doesn't exist.
Return True
End Sub
Works perfectly on my iPad Erel, very elegant solution!
For ABMaterial users:
In ABMApplication add in ABMApplication in both StartServer and StartServerHTTP2:
B4X:
' start the server
srvr.Initialize(srvrName)
srvr.AddFilter("/js/b4j_ws.js", "ABMSessionCreator", False) ' <----- Add this line
srvr.AddWebSocket("/ws/" & AppName, "ABMApplication")
...
Create a new Filter class ABMSessionCreator and add:
B4X:
'Filter class
Sub Class_Globals
End Sub
Public Sub Initialize
End Sub
'Return True to allow the request to proceed.
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
req.GetSession 'a new session will be created if a session doesn't exist.
Return True
End Sub