HttpSession session=requestObj.getSession();
ArrayList<String> items=(ArrayList<String>)session.getAttribute("itemlist");
items.add(newitem);
In this code, why don't I need to set attribute
setAttribute("itemlist",items)
back to session object eventhough I updated the data in this session.
And as far as I know, session data are stored in server. So, when these data are sent to server?
You don't have to do ----setAttribute("itemlist",items)---because you have a reference to itemlist which you have stored in items.
ArrayList<String> items=(ArrayList<String>)session.getAttribute("itemlist");
So any changes you make to "items" will be visible in the "itemlist" attribute.
The data are sent to the server when you submit the form. A form could be submitted by clicking a submit button.
Your code is in Java, so I'm guessing it is running on the server already?
If you only have one server process, then you are directly modifying the same in-memory reference to the list which is already stored in the server session, so you will automatically see the changes.
However, you should actually call setAttribute any time you modify the state. If you are running in a cluster, or a cloud environment like Google App Engine which may be running multiple copies of your app, then this call will be used to propagate changes to the other processes.
Related
i am working on a chatbot and need to save context of the previous conversation so that it can be sent to the next message. Now i m integrating it with facebook where facebook doesn't send context and need to store this context somewhere in a server. my client doesn't want to use DB. i tried sessions but technically i dont have a UI (facebook is the UI) . Next i tried ehcache but not able to retrieve data of previous webhook calls. Please let me know if any there is a method to store data and retrieve it latter without using DB.
What you describe is not really a cache usage from what I can tell. That is you do not want to have entries disappear (eviction) and they do not get stale (expiration).
If that is correct, you will need to use the appropriate in-memory data structure so that you can store that information.
being more specific would require a bit more information about your system, the volume of data (per entry and max entries at once), etc ...
I'm using the Unity API. I let a user delete their own account. It's accomplished via ParseUser.CurrentUser.DeleteAsync()
I then call ParseUser.CurrentUser.LogoutAsync(); to delete the local ParseUser object on their device.
This works, but afterwards, the now-deleted user's session is still up, buty the associated user field is now a broken link.
How can I end this session? I tried to get a reference to the session before deleting the user via ParseSession session = ParseSession.GetCurrentSessionAsyn(), deleting the user, and then the session, but the session.DeleteAsync() fails.
Edit (clarification):
I check all Tasks that return from my various function calls. I detect when things fail, and that's how I know my ParseSessions aren't being deleted (plus, they're showing up in Parse's CORE session list).
I just can't find a way to make sure the session is ended from the client's side.
DeleteAsync returns a Task Object. Try using that object to ensure that the deletion has completed prior to calling LogoutAsync()
We are using Asp.net Session in our application for state management. By default, In-proc mode is being used. But now, we have to look for an alternative as we have been asked to remove Session from our application by our client due to performance issue.
One of the way is to keep everything at Client side say in hidden field on Postback. It's not a good approach for sure.
Is there any other way of doing it? Im sure there would be an alternative.
PS: Please don't suggest Querystring.
Thanks,
Sumit
Something close to that is HttpContext.Current.Items but has a shorter life span
Items collections of HttpContext is and IDictionary key-value
collections and that are shared across a single HTTPRequest. Yes,
HttpContext.Current.Items valid for a single HTTPRequest. Once
after processing, server information is sent back to the browser,
the variables that were set in the Items[] collection will lost. Where
as for Session Variable, information valid for multiple request as
this is user specific. The session variable only expires either on
Session Time Out or explicitly clear the values.
More from these articles
When we can use HttpContext.Current.Items to stores data in ASP.NET
Here's the issue at hand: I have developed an ASP.NET MVC3 application using Razor. I have also implemented a custom membership provider and overridden the ValidateUser() method. Within, I query my db and get a lot of user information in addition to the password auth.
At the moment, I am pushing this information, i.e. companyId, to static properties of a class. This works and I can display/use this information throughout my app. The problem arises when a user closes their browser tab. Upon re-opening the app, the user is authenticated via a cookie, so they don't need to re-login; however, those static variables are blown away.
So guys and girls, how would/do you conquer this issue? Should I append the extra info to the session cookie? Or perhaps a better solution?
Use the ProfileProvider in ASP.NET.
For application level variables, they are going to be subject to application pool recycles and similar "simulated" restarts related to users starting all over. These variables should be completely independent of user usage and should be able to be recreated easily. If you have variables that are user dependent or that can't be restored easily without some sort of outside intervention then you will definitely need a different method of storage.
If the data is user specific, storing it in the session cookie is probably the best idea. If the data is user-related but branches multiple users it should be stored in a database or a flat file somewhere. If the data has nothing to do with users specifically then it should just be in a database or configuration file.
I'm trying to integrate a public message board service into an existing web site.
The handshaking between the apps goes like this:
1) File on my web site loads a flash file. The Flash reads a local variable that is the Session ID, or some other GUID unique to the user session.
2) Flash app connects with the remote service, passing the SessionID to the service.
3) The service issues a GET request back to the originating web site, asking for additional information about the user.
4) The originating web site (my site) validates that the session ID is for a valid session, and if yes, passes back the other requested information.
I'd like to be able to use the intrinsic ASP SessionID but I'm not sure how in Classic ASP to retrieve session variables for a specific ASP Session, ie, I want the value of Session("FirstName") where SessionID=1234 and not Session("FirstName") for any other session ID. I haven't been able to find any syntax that would allow me to do this.
The alternative is to create a new GUID for every session, but that's adding a lot of overhead.
Any ideas?
I'm not aware of any way to retrieve Session details for a particular instance or ID.
However, you could utilise the Application object to store the information you need using the Session.SessionID value:
Application(Session.SessionID & tag) = myTagValue
This way you are not creating a new GUID, but utilising the already existing one for session that both client and server are using in your example.