純Jsp頁面登陸失敗彈出窗口(不鏈接數據庫)

這是登陸界面:login.jsp
<%
@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>登陸界面</title> <% if("login_error".equals(request.getParameter("message"))){ %> <script type="text/javascript"> alert("用戶名或者密碼錯誤!"); </script> <%}else{%> <!-- 沒有收到任何錯誤信息 --> <% }%> </head> <body> <form action="loginAction.jsp" method="post"> 用戶名:<input type="text" name="userName"><br>&nbsp;&nbsp;&nbsp;&nbsp;碼:<input type="password" name="userPwd"><br> <input type="submit" name="btnLogin" id="btnLogin" value="登陸"> </form> </body> </html>
這是業務邏輯運算界面:login_action.jsp(後臺運行不顯示)
<%
@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% //後去刻畫段的發送上來的兩個參數(post方法發送過來的編碼不是UTF-8String name =request.getParameter("userName"); String pwd = request.getParameter("userPwd"); //解決中文所產生的亂碼,對兩個參數進行轉碼,從默認的iso-8859-1轉爲UTF-8,這是一個很很差的解決方法 name = new String(name.getBytes("iso-8859-1"),"UTF-8"); pwd = new String(pwd.getBytes("iso-8859-1"),"UTF-8"); if( "kobe".equals(name) && "123".equals(pwd)){ //登陸成功,設置session,標記一下這個用戶已經登陸 session.setAttribute("user",name); //跳轉到成功的後臺頁面console.jsp response.sendRedirect("console.jsp"); }else{ //登陸失敗,響應客戶端,讓客戶端從新發出新的請求(登陸界面) response.sendRedirect("login.jsp?message=login_error"); } %>
這是登陸成功頁面:Ok.jsp
<%
@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <h1 align='center'>登陸成功!湖人總冠軍!</h1> <h1 align='center'>歡迎${user}</h1> </body> </html>

輸入錯誤的帳號或者密碼之後顯示的結果javascript

成功後的結果html

相關文章
相關標籤/搜索