会话对象返回 null
我为我的项目“学生信息系统”创建了一个登录页面,其中包含文本字段用户名、用户 ID 和密码。我尝试将用户名和用户 ID 的值存储在会话对象中并在另一个页面中使用它,但它返回空值。
i have created a login page for my project "student information system" which contain text fields username,userid and password.i tried to store the value of username and userid in session object and use it in another page but it is returning null value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几个原因:
session.setAttribute(key, value)
完成)。session.invalidate()
)。session.getAttribute(key)
或${key}
完成)。下面的
login.jsp
示例....有一个映射到
/login
的 servlet,它在doPost()
中基本上具有以下内容... .和一个看起来像这样的
home.jsp
..应该可以工作。
确保两个页面中的会话 ID相同。出于调试目的,您可以通过
${pageContext.session.id}
查看它,如上面的 JSP 代码片段所示。如果相同并且User
对象仍然不存在,则问题出在其他地方。Several causes:
session.setAttribute(key, value)
).session.invalidate()
).session.getAttribute(key)
or${key}
).The following
login.jsp
example....with a servlet mapped on
/login
which has basically the following indoPost()
....and a
home.jsp
which look like this....should just work.
Ensure that the session ID is the same in both pages. For debugging purposes you can view it by
${pageContext.session.id}
as shown in the above JSP code snippets. If it is the same and theUser
object is still not there, then the problem lies somewhere else.