重定向到相同的页面,但有消息 [英] Redirect to the same page but with a message in it
问题描述
我正在JSP中创建一个登录页面。我有一个 index.jsp
页面,其中存在表单和一些javascript脚本。连接到oracle数据库并检查数据库中的用户名和密码是在 check1.jsp
file
中完成的。我的问题是输入用户名和密码后,当我按下登录按钮时,我已将表单链接到 check1.jsp
,如果用户名和密码匹配并存在,它将重定向到 welcome.jsp
,但是如果用户名不存在或密码不匹配,我必须回到 index.jsp
,显示在用户名不存在的情况下输入小信息或密码不匹配,目前我只是重定向到 index.jsp
。
如何在同一个 index.jsp
页面上的登录框下显示适当的小信息?
您可以使用 session
对象在这里:
check1.jsp
: if(loginSuccess){
//重定向到welcome.jsp
}
else {
session.setAttribute(error,用户名或密码不正确);
//重定向到index.jsp
}
在 index.jsp
:
String msg = session.getAttribute(error);
if(msg!= null){
%>< p style =color:red><%= msg%>< / p><%
}
EL和JSTL还有其他更简单的方法,但它仅仅用于启动小费。
I am making a login page in JSP. I have an index.jsp
page where exist the form and some javascript scriplets. Connectivity to oracle database and checking for username and password in database is done in check1.jsp
file
My issue is after entering username and password, when I press login button, I have linked the form to check1.jsp
, if username and password matches and exist, it redirects to welcome.jsp
, but if username doesnot exist or password is not matched I have to get back to index.jsp
showing a small message below box that username doesn't exist OR Password is not matched, currently I am just redirecting to index.jsp
.
How should I show that appropriate small message below login box on that same index.jsp
page??
You can use session
object here:
In check1.jsp
:
if (loginSuccess) {
//redirect to welcome.jsp
}
else {
session.setAttribute("error", "Username or Password is incorrect");
//redirect to index.jsp
}
In index.jsp
:
String msg = session.getAttribute("error");
if (msg != null) {
%><p style="color:red"><%= msg %></p><%
}
Also there is other more simpler ways exists with EL and JSTL, but its just for an starting tip.
这篇关于重定向到相同的页面,但有消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!