是否可以使用 GWT 在浏览器缓存中存储变量(最好是字符串)?
我一遍又一遍地搜索谷歌,但找不到任何关于在缓存中存储变量的信息。我所看到的与此事相关的任何事情看起来都非常复杂并且没有得到很好的解释。我正在使用 GWT 设计一个非常简单的登录系统,使用一个文本文件,根据用户是否登录或注销分别附加 true 或 false 来编辑用户行。
问题是,当用户刷新窗口时,他们没有注销(因为我不希望他们注销),但应用程序已经丢失了当前的用户变量,因此看起来他们已注销。我想缓存当前用户的用户名,直到他们注销,以便我可以允许用户刷新/关闭选项卡并仍然登录。我正在寻找相当深入的解释,因为我以前几乎没有经验带缓存!如果问题看起来很愚蠢或无法解决,请告诉我!
I have trawled Google over and over but I cannot find anything about storing a variable in the cache. Anything I have seen related to the matter looked very complicated and was not well explained. I am designing a very simple login system with GWT using a text-file that edits a users line by appending true or false depending on whether they are logged in or out respectively.
The problem is that when the user refreshes the window they are not logged out (because I don't want them to be) but the application has lost the current user variables so it appears that they are logged out. I would like to cache the username of the current user until they logout so that I can allow the user to refresh/close the tab and still be logged in. I am looking for quite an in depth explanation as I have little/no previous experience with caching! If the question seems stupid or a solution is not possible please tell me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
设置 Cookie 比这里描述的要容易得多!我只给你一个例子:
来源:Set Cookies with GWT申请将在预期时间段后过期,类 Cookie
Setting Cookies is way easier than described here! I'll just give you an example:
Sources: Set Cookies with GWT applications to expire after expected time period, Class Cookies
HTML5 是我能找到的最好、最简单的解决方案。
我使用了 GWT Storage API,可以在 Eclipse 中的此处找到该 API这非常简单。如果其他人想做类似的事情,所有内容都会在我提供的链接中进行解释。
HTML5 was the best and most simple solution that I could find.
I used the GWT Storage API which can be found here in Eclipse and it was extremely simple. If anyone else wants to do a similar thing everything is explained in the link I provided.
GWT 不提供任何在浏览器中存储值的选项,但您可以使用“cookie”在浏览器上存储数据。 GWT 将帮助您在浏览器上创建和维护 cookie。如果您计划在浏览器上存储更多数据,请使用 HTML 5 功能。
带有 GWT 的 Google Gear 也是在浏览器上存储数据的一个选项
GWT does't provide any options for storing value in browser but you can use 'cookie' to store data on browser. GWT will help you to create and maintain cookie on browser. If you are planing to store more data on browser use HTML 5 features.
Google Gear with GWT is also an option to store data on browser
您可以将数据存储在用户会话中,并通过 RCP 从服务器 onModuleLoad()(或任何您需要的时候)获取数据。从安全角度来看,将登录状态存储在客户端上是一个坏主意,因为他可以将其更改为“已登录”。
You could store the data inside the user session and fetch it from the server onModuleLoad() (or whenever you need it) via RCP. It is a bad idea from a security point of view to store the login state on the client because he could change it to "logged in".