1. 程式人生 > >在servlet中彈出對話方塊

在servlet中彈出對話方塊

簡單的登入驗證模組
點選登入進入相應的Servlet,Servlet呼叫bean驗證使用者名稱是否存在
如果存在則登入成功,跳轉
如果不存在則彈出錯誤對話方塊,並回到登入頁面
開始用的下面兩句話
out.print("<script language='javascript'>alert('the name doesnot exit')</script>");
response.sendRedirect("Login.jsp");
但不會顯示對話方塊,而是直接回到Login.jsp
後來改用
JOptionPane.showMessageDialog(null, "name doesnot exits");
response.sendRedirect("Login.jsp");


則可以實現。

把response.sendRedirect("Login.jsp");去掉,然後
out.print("<script language='javascript'>alert('the name doesnot exit');window.location.href='Login.jsp';</script>");