简体   繁体   English

为什么这个request.getParameter()不起作用?

[英]Why is this request.getParameter() not working?

I have a simple login page (login.jsp) and I'm checking it against a database to verify user credentials. 我有一个简单的登录页面(login.jsp),正在针对数据库进行检查以验证用户凭据。 This is just for testing, not for making an actual site. 这仅用于测试,而不是用于创建实际站点。

In the verification servlet where the values are checked against the DB values, if there is not a match I do a 在验证Servlet中,对照DB值检查值,如果没有匹配项,则执行

response.getRedirect("login.jsp?loginfailed=true");

This, obviously, sends me to 显然,这使我转向

localhost:8080/blahblahblahblah/login.jsp?loginfailed=true 本地主机:8080 / blahblahblahblah / login.jsp?loginfailed = true

which is what I want. 这就是我想要的。 But then, in the jsp file, I do 但是然后,在jsp文件中

<%
    if(request.getParameter("loginfailed") == "true")
    {
        out.println("login failed");
    }
%>

I'm well aware that I should replace this with JSTL , it's just easier for me to use scriptlets at first for control flow and I change them out once the logic works. 我很清楚我应该用JSTL代替它,这对我来说首先使用scriptlet进行控制流更容易,并且一旦逻辑起作用,我就将它们替换掉。

I just don't know why it is not working right now. 我只是不知道为什么它现在不起作用。 What am I doing wrong? 我究竟做错了什么?

Basically when credentials DO match DB values, it redirects to a success page. 基本上,当凭据确实与数据库值匹配时,它将重定向到成功页面。 But if they don't, it redirects back to login.jsp with a URL param, and I want to print some text that says the login failed so the user doesn't have to look at the url to see that. 但是,如果没有这样做,它将使用URL参数重定向回login.jsp,我想打印一些文本,指出登录失败,因此用户不必查看url就可以看到。

your redirection should be in this way. 您的重定向应采用这种方式。 response.sendRedirect(request.getContextPath()+"/login.jsp?loginfailed=true"); response.sendRedirect(request.getContextPath()+“ / login.jsp?loginfailed = true”);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM