在同一页面上显示错误消息,并且在JSP中有一个Session? [英] Showing error message on same page with a Session in JSP?
问题描述
在这种情况下,我需要显示用户未输入正确密码的位置,程序将在会话中放置适当的消息,将分派回登录jsp页面并显示消息.
I have this situation where I am required to show where if user does not enter right password, the program will place an appropriate message in a session & will Dispatch back to the login jsp page and display the message.
我也检查了这个,重定向到同一页面但其中有一条消息
但是当我尝试实现答案时,日食使我在代码上出现了一条红线.
But when I try implement the answer, the eclipse gives me a red line over the code.
这是我的代码,
String message = "Wrong Password!";
HttpSession session = session.setAttribute("message", message);
显示的错误为类型不匹配:无法从void转换为HttpSession
有什么想法我错了,或者我该怎么做?
Any ideas where I am wrong or how can I do this?
推荐答案
session.setAttribute("message", message);
此返回类型为空,因此您对HttpSessoin
对象进行了设置,因此显示了编译器错误.
this return type is void, hence your pionting to HttpSessoin
Object, so it is giving showing complier error.
使用此
HttpSession session = request.getSession(true);
session.setAttribute("message", message);
这篇关于在同一页面上显示错误消息,并且在JSP中有一个Session?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!