如果用戶登錄失敗,我寫了一個代碼來顯示錯誤消息。小服務程序代碼如下:無法在瀏覽器窗口中查看警報
HttpSession session = request.getSession(true);
/*User class is a Java bean with an isValid attribute*/
User user= new User();
if (!user.isValid()) {
request.setAttribute("errorMessage"," Invalid Parameters!");
request.getRequestDispatcher("RegistrationPage.jsp").forward(request, response);
}
// RegistrationPage.jsp file code snippet is below
<script>
function loginFailure() {
System.out.println("Invalid parameters");
if(request.getParameter("errorMessage") != null) {
alert("<%= request.getParameter("errorMessage") %>");
}
</script>
<body onload="loginFailure()">
</body>
我不明白爲什麼頁面在登錄失敗時不顯示警告消息。它確實進入了loginFailure的方法和alert函數。
它不應該是'的getAttribute( 「的errorMessage」)'你scriplet? –