【问题标题】:How to redirect and show error message without using session in jsp?如何在不使用jsp会话的情况下重定向和显示错误消息?
【发布时间】:2017-03-17 13:34:42
【问题描述】:

我有一个表格:

<form action="login" method="post" name="loginForm">
    User Name: <input type="text" name="userName" autofocus>
    Password: <input type="password" name="pwd">
    <input type="submit" value="Login">
    <a href="register.jsp">Register</a>
</form>

现在每当我点击提交按钮时,它都会在地址栏中显示 /login。如果用户或密码不匹配,我希望它显示 /index.jsp 并显示错误消息。 我使用了 sendRedirect 方法,但如何发送错误消息?如果我必须使用会话,那么我也必须删除该属性。如果我不想使用 session 并且仍然想发送错误消息怎么办?我怎样才能做到这一点?

【问题讨论】:

  • 然后你必须将你需要的信息作为 GET 参数传递给索引页面。
  • 如果您不想使用会话,为什么要首先登录?您想在哪里存储用户已成功登录的信息?您想重新实现您自己的会话处理方式吗?

标签: java jsp session


【解决方案1】:

试试这个:

response.sendRedirect("/index.jsp?error=something");  

然后像这样从jsp 中检索param

Error message :  <%= request.getParameter("error") %>!

【讨论】:

  • 感谢您的回复。但是我的浏览器显示这个 index.jsp?loginErrorMsg=+Either+User+Name+or+password+is+wrong 我可以在地址栏中阅读它。那么如何对整条消息进行编码,这样没人会通过查看地址栏了解发生了什么。
  • @run_time_error 表单与 Get 方法显示数据/属性值,Post 方法表单不显示它。
猜你喜欢
  • 1970-01-01
  • 2014-04-10
  • 1970-01-01
  • 2014-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-19
  • 2022-11-23
相关资源
最近更新 更多