如何在Servlet代码中警告消息并发送重定向到JSP页面? [英] How can I alert message in Servlet code and sendredirect to JSP page?

查看:246
本文介绍了如何在Servlet代码中警告消息并发送重定向到JSP页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图制作一个简单的登录页面来处理使用JSP,具有MVC概念的servlet和数据访问对象(DAO)的数据库,这是我的新手.现在的问题是,如果用户输入了无效的名称和密码,并再次将sendRedirect发送到login.jsp页面,则需要在servlet中发出警告消息.如果用户有效,我将标志设置为1,然后执行if-check

I am trying to make a simple login page to deal with database using JSP, servlet with MVC concept and Data Access Object(DAO) and I am new in this. My problem now that I need to alert a box message in servlet if the user enters invalid name and password and sendRedirect to login.jsp page again. I set flag to be 1 if the user valid then do this if-check

if(validUserFlage == 1)
    response.sendRedirect("User_Manipulation_Interface.jsp");
else {   
    //Here i want to alert message cause user invalid ??
    response.sendRedirect("Admin_And_User_Login_Form.jsp");
}

寻找这个,我找到了这个答案,但是我不明白我该怎么做 我找到的答案: ((使用send redirect时,您无法在代码中所需的位置显示消息.按照我的观点,可能有两种方法.在此处显示消息,并使用include的requestdispatcher代替send redirect,否则将一些消息传递给admin.jsp和在此处显示消息.)

searching for this i find this answer but i can`t understand how can i do it the answer i found: (( With send redirect you cant display the message where you want in the code. So as per me there might be two approaches. Display a message here and use include of requestdispatcher instead of send redirect or else pass some message to admin.jsp and display the message there. ))

推荐答案

设置这样的标志参数,

 response.sendRedirect("Admin_And_User_Login_Form.jsp?invalid=true");

在jsp上

<c:if test=${invalid eq 'true'}">invalid credentials</c:if>

这篇关于如何在Servlet代码中警告消息并发送重定向到JSP页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆