Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Jute Powerful Forum  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 jute把session信息写在cookie中的利弊之我见
yadan



Jute User


发贴: 226
积分: 30
于 2003-01-05 22:05 user profilesend a private message to usersend email to yadansearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
jute没有用servlet中的session,而是把session信息写在cookie中,按照rainman的说法是节约服务器的资源,有没有具体的证据呢?

这种机制在使用中有点不方便的是:每台机器只能用一个帐户登录一个地址,(tom社区也是这样。那时候为了抢金币练功,多个帐户来回切换着实把我忙坏了,呵呵)当然这样的限制也不是不可,但如果可以让同个机器用多个帐户,至少可以一边用后台的管理工具,一边在前面发贴,呵呵



作者 呵呵,你的提法有意思! [Re:yadan]
rainman

阿熊

元老


发贴: 5644
积分: 454
于 2003-01-05 23:47 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
因为用服务器的Session写程序当然更简单一点。但带来的问题就是不能load banlance (当然有些服务器支持分布式Session)。

本来这样做就是为了防止一台机器同时用多个帐户哦!

如果你需要一台机器用多个账号也不是没有办法的,你可以选择临时登录方式。这样就可以一台机器多次登录了。


rainman edited on 2003-01-06 11:15


作者 jute用这种方法支持分布式的服务器吗? [Re:yadan]
yadan



Jute User


发贴: 226
积分: 30
于 2003-01-06 09:14 user profilesend a private message to usersend email to yadansearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
right?


作者 Re:jute把session信息写在cookie中的利弊之我见 [Re:yadan]
floweret



Jute User


发贴: 37
积分: 0
于 2003-01-06 09:35 user profilesend a private message to usersend email to floweretsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我原来开发过一些网站,也比较关心用户登陆的机制。谈谈我的一些看法。
我觉得用session记录是非常方便的,但是session是耗内存的,而且在需要跨服务器时需要额外的支持。所以我用cookie加数据库的形式模拟session。我在用户登陆时写2个cookie,一个是用户名还有一个是用md5编码的随机字符串,并在A_loginUsers表中记录用户名,用户次登陆的IP,登陆时产生的随机字符串以及登陆时间。
然后在每个需要登陆的页面我都会用以下sql语句验证:

"select lastChkTime from A_loginUsers where userName='"
+SuccessUserName+"' and rndChkFlag='"+abSimulateSession+
"' and userIP='"+getUserREMOTE_ADDR+"' and DATE_ADD
(lastChkTime,INTERVAL 1200 SECOND)>='"+nowTime+"'"

SuccessUserName是存在客户端中的cookie,abSimulateSession是登陆时写在客户端的随机字符串。getUserREMOTE_ADDR是取得现在用户的IP。只要这3项有任何一项不符,就认为是非法登陆。这样用户即使能更改cookie中的用户名,因为随即码不同也不能登陆。

+"' and DATE_ADD(lastChkTime,INTERVAL 1200 SECOND)>=
'"+nowTime+"'"
是判断用户是否登陆超时。如果不需要超时判断可以将这句去除。

以上是我习惯用的用户登陆机制,如果有更好的,效率更高的方法请提出来让我学习学习啊,大家一起进步 SmileSmileSmile


floweret edited on 2003-01-06 09:37

如果这天地最终会消失,不想一路走来的记忆没有你...
作者 提个意见 [Re:yadan]
floweret



Jute User


发贴: 37
积分: 0
于 2003-01-06 09:40 user profilesend a private message to usersend email to floweretsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
关于技术的一些讨论能不能不加密呢。大家可以一起学习啊 Shock


另外,拜托各位老大少发什么积分大于1才能看的帖子好吗?总是看到关键内容就没了.......呜呜,菜鸟们也想多了解点东西啊。再说大家到坛子里都是为了交流,了解多些对jute的宣传和发展没有坏处哦....

yadan edited on 2002-12-25 11:36


agree
DeadDeadDead


floweret edited on 2003-01-06 09:45

如果这天地最终会消失,不想一路走来的记忆没有你...
作者 Re:jute把session信息写在cookie中的利弊之我见 [Re:floweret]
yadan



Jute User


发贴: 226
积分: 30
于 2003-01-06 10:06 user profilesend a private message to usersend email to yadansearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看了floweret 的方法很受启发,我作登录验证都是用session的。
我估计jute的方法和floweret的差不多,rainman是不是?



作者 Re:jute把session信息写在cookie中的利弊之我见 [Re:floweret]
rainman

阿熊

元老


发贴: 5644
积分: 454
于 2003-01-06 11:07 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
很好的方法。某一时刻已经登录的用户也很容易从这张表里取出来。

聊两句:
这张表首先应该是不同于用户表(用户表一般比较大,或者从LDAP里来),但因为同一时刻网站上的人不多,所以可以用临时的登录信息表来存(这和Jute的在线情况表相似)。这张表按你的设计应该按查询优化咯,而Jute的Online表是需要按更新优化。




作者 对啊, 绝对支持哦! [Re:yadan]
rainman

阿熊

元老


发贴: 5644
积分: 454
于 2003-01-06 11:07 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
可以在同一个domain下保持登录状态。



作者 Re:jute把session信息写在cookie中的利弊之我见 [Re:yadan]
rainman

阿熊

元老


发贴: 5644
积分: 454
于 2003-01-06 11:09 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
yadan wrote:
看了floweret 的方法很受启发,我作登录验证都是用session的。
我估计jute的方法和floweret的差不多,rainman是不是?


比较相同哦!不过是取出数据来比较,而不是用数据库的比较(数据库要做三次比较),把这个负载放到前端来了。




作者 Re:jute把session信息写在cookie中的利弊之我见 [Re:yadan]
gnome



发贴: 0
积分: 0
于 2003-02-20 15:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
关于这个问题我的看法:
(1)Load balancing的粒度可以是请求,也可以是用户session,个人觉得这两者的性能差别在大范围内不会有太大的差别,所以用cookie实现request级别的load balancing意义不是很大,而且resin/tomcat应该支持的是session级别的load balancing吧。
(2)如果说用于节约空间,那么使用类似外存的方式显然更加有效,这类似前面说的cookie+mysql的方式,不过mysql只是作为一个长期idle的session的备份,内存中尽量保存活跃的session。不过这要求session中的内容必须是"persistentable"的。



作者 Re:jute把session信息写在cookie中的利弊之我见 [Re:gnome]
rainman

阿熊

元老


发贴: 5644
积分: 454
于 2003-02-20 16:33 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
"所以用cookie实现request级别的load balancing意义不是很大" ?
Tomcat有支持Session的load balancing吗?我记得早期的版本是没有的,最新的估计也没这个功能吧?如果为了跨服务器运行,这样做就很有必要了。性能方面这样做也很好啊,天晓得应用服务器的Session实现得好不好。
还要一个原因是为了跨应用实现一次登录,两台服务器用不同的语言写的应用,比如一个是perl写的短消息应用,一个是Jute,那Session就没辙了。

“类似外存的方式显然更加有效",Jute这样不是更有效吗?哪里显得效率低了?




作者 Re:jute把session信息写在cookie中的利弊之我见 [Re:rainman]
gnome



发贴: 0
积分: 0
于 2003-02-20 21:36 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
tomcat如果没有支持session的load balancing我就可以撞墙了,呵呵,似乎早在jserv的年代就有了,这个又不是什么困难的技术,无非是根据sessionid决定虚拟机而已。tomcat比较新的版本对于多虚拟机似乎有更复杂的支持,不过我好久不用tomcat,不是非常清楚。
我觉得全部写在cookie里面倒是有一个好处,就是session不会因为某个服务器的failure而丢失,记忆中似乎有servlet container实现了这个功能;跨服务器运行倒并不必须如此了。
至于效率,你误会我的意思了,我并不是说jute这样的效率不高。我的意思是即使不改变原来服务器内存session的使用,也可以达到这样的效果,无非就是把长久不用的session swap到可靠存贮(数据库/磁盘),这样上层都不需要做任何改动就能达到目的。resin的session机制非常多,比如Database based, sticky session,总有一款是适合你的Smile 当然,自己做的好处就是“一切自在掌握”,起始我也挺喜欢这样的。
至于说和perl等其他语言的合作,那我就无话可说了,除了cookie,你也没有别的办法,对吧。



作者 Re:jute把session信息写在cookie中的利弊之我见 [Re:gnome]
rainman

阿熊

元老


发贴: 5644
积分: 454
于 2003-02-21 02:14 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
session load balancing没那么简单哦,不光是虚拟机的问题啊。一个复杂的应用环境里依赖Servlet engine来做这件事,不是很可靠。不过你的意见不错啊,给你加分了。



作者 Re:jute把session信息写在cookie中的利弊之我见 [Re:yadan]
floater

Java Jedi

总版主


发贴: 3233
积分: 421
于 2003-02-21 02:55 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
I am a lazy guy, I use hardware load balancers, Big Smile. Kidding, but I have been using it for 2 years.

Good discussion!

One question, is load balancing feature supposed to be at the app server level and applications shouldn't worry about it at all?

Cookies are good for single signon too. There could be a lot of totally different ways to A&A, so it would be better to use cookies here.

The login user table should be isolated from the application too. If you have 500 applications and layers of firewalls, for security reason, you would have to consolidate these tables into one place outside the applications(so cookies have another advantage in here too).



"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
- Martin Fowler, Refactoring - Improving the Design of Existing Code

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923