Java桌面应用程序有一个会话 [英] Java desktop application do it has a session

查看:62
本文介绍了Java桌面应用程序有一个会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java桌面应用程序有没有会话?我是一个初学者登录成功使用mysql数据库现在我想存储谁登录他的ID在会话中所以我可以使用它在不同的



请帮助me.i我没有使用任何使用java netbean的框架,它是一个桌面应用程序而不是jsp



我尝试过:



java桌面应用程序是否有会话

解决方案

会话是特定于单个用户的服务器端缓存。用于访问缓存的会话ID通常存储在客户端。每当发出Web请求时,会话ID都会在请求标头中发布。

如果你想存储任何用户都可以访问的全局内容,你必须使用实际的Cache对象或普通的旧字典。





在桌面应用程序上,一切都是用户特定的,因为只有一个会话打开。您可以使用实际的Cache。通常使用字典对象。

字典(Java平台) SE 7) [ ^ ]



如果您的应用程序调用Web服务,则每次会话都是新鲜的,因为每次调用都是新连接。因此,您不应该在Web服务中使用会话对象。



您可以使用唯一ID模拟缓存并将其传递给Web服务以确定谁是连接。因此,许多高级网络api通过在请求网址中包含唯一ID来实现。



如果您的应用程序以其他方式连接到服务器服务,那么您将不得不照着做。



如何确定唯一ID取决于您。如果您在安全网络中进行连接,则可以使用用户名或计算机名。或者只是在应用程序启动时创建的任何随机guid。如果你没有在安全的网络中连接,那么使用guid或上面的哈希。






我希望这有帮助^ _ ^如果没有那么请说明您的实际要求是什么,我很乐意与您探讨更多选择。



Andy


我计划将数据库设置为本地服务器,客户端计算机将在登录期间访问,我需要登录的每个用户ID,以便我可以跟踪。在php中我们在会话中使用dot net也使用session



i不知道java为那做什么或者叫做。我使用了一个全局变量,它可以正常工作1个不确定它是否适用于其他相同或不同的

java desktop application do it has a session? i am a beginner made login successfully using mysql database now i want to store who is login his id to be in session so i can use it in different from

please help me.i am not using any framwork using java netbean and it is a desktop application not jsp

What I have tried:

java desktop application do it has a session

解决方案

Session is a server side Cache specific to a single user. The session id used to access the cache is usually stored on the client side. Whenever a web request is made, the session id is posted in the request header.
If you want to store something globally that can be accessed by any user you have to use an actual Cache object or a plain old dictionary.


On a desktop application, everything is user specific because there is only one "session" open. You can use an actual Cache instead. Dictionary object are usually used.
Dictionary (Java Platform SE 7 )[^]

If you application calls a webservice then the session is fresh every time because each call is a new connection. Therefore you should not use session objects in web services.

You can "emulate" a cache by using a unique id and passing it to the web service to identify who is connecting. Many premium web apis do thus by having the unique id included in the request url.

If your application connects to a server service in some other way then you will have to do the same.

How you determine the unique id is up to you. If your connecting within a secure network then you could just use username or computer name. Or just any random guid created on application start. If you are not connecting within a secure network then either use a guid or a hash of the above.



I hope that helped ^_^ If not then please specify what your actual requirement is and I'll be happy to explore more options with you.

Andy


i am planing to set database to a local server and client computer will access that during login i need each user id who login so i can track.in php we do in session in dot net also use session

i don't know what java do for that or called.i used a global variable which working fine for 1 pc not sure it will work for other pc same or not


这篇关于Java桌面应用程序有一个会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆