gpt4 book ai didi

java - JSP和Servlet中用户使用Session登录失败时的错误消息

转载 作者:行者123 更新时间:2023-12-01 13:40:59 25 4
gpt4 key购买 nike

我的目标是在用户无法登录系统时创建错误消息。我设法使用 session 创建错误消息。

但是,当我刷新浏览器时,错误消息仍然存在。它不应该出现。有没有办法让我在用户刷新浏览器时使错误消息不可见?

下面是我的代码。帮助将不胜感激..谢谢! :)

login.jsp

<div class="error">
<% String e = (String) session.getAttribute("error" );
if(e != null)
{
out.print(e);
}%>
</div>

Servlet

HttpSession session = request.getSession(true);
session.setAttribute( "error", "Invalid username or password");
RequestDispatcher dispatcher = request.getRequestDispatcher("/login.jsp");
dispatcher.forward( request, response);

最佳答案

session 属性在 HttpSession 的持续时间内有效。尝试使用请求属性

request.setAttribute( "error", "Invalid username or password");

仅在请求期间持续。

否则,您必须从 HttpSession 中删除该属性。

关于java - JSP和Servlet中用户使用Session登录失败时的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20778342/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com