在.jsp中登录系统 [英] Login system in .jsp

查看:199
本文介绍了在.jsp中登录系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含登录表单的login.jsp页面。一旦登录,用户将被带到index.jsp,这个index.jsp应该知道哪个用户登录了。如果用户刷新页面,他将保持登录状态,而不会被带回到login.jsp。所以需要进行某种会话。我搜索了一个例子,发现了Java bean,但实际上并没有理解它。有人可以帮我解决这个问题,而不是必需的Java bean。



在此先感谢=]

解决方案

这可以通过使用会话对象完成:

 <%
字符串名称=testme;
session.setAttribute(theName,name); //作为会话对象中的一个属性写入
%>

以及一段时间后您可以这样做:

 <%String name = session.getAttribute(theName)%> //从会话中退出属性

在这里查看简单介绍:
http://www.jsptut.com/Sessions.jsp


I have a login.jsp page which contains a login form . Once logged in the user will be taken to index.jsp and this index.jsp should know which user is logged in . If the user refreshes the page he will stay logged in and not taken back to the login.jsp. So there need to be some sort of session. I searched for an example and found about Java bean ,but didn't actually understand it. Can someone help me with this ,not necessary Java bean.

Thanks in advance =]

解决方案

This can be done by using the session object:

<%
   String name = "testme";
   session.setAttribute( "theName", name ); //write as an attribute in the session object
%>

and some time later you can do:

<% String name= session.getAttribute("theName")%> // retireve the attribute from the session

check here for a simple introduction: http://www.jsptut.com/Sessions.jsp

这篇关于在.jsp中登录系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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