為什么我輸入指定的用戶名和密碼后,總是無法跳轉(zhuǎn)到登錄成功的頁面,只能到登錄失敗的頁面?
代碼如下:
login.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? <head>
? ? <base href="<%=basePath%>">
? ??
? ? <title>My JSP 'login.jsp' starting page</title>
? ??
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"> ? ?
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
? </head>
??
? <body>
? ? <div id="container">
? ? <div class="logo">
? ? <a href="#"><img src="assets/logo.png" alt=""></a>
? ? </div>
? ? <div id="box">
? ? <form action="dologin.jsp" method="post">
? ? <p class="main">
? ? <label>用戶名:</label>
? ? <input name="uername" value="">
? ? <label>密碼:</label>
? ? <input name="password" type="password" value="">
? ? </p>
? ? <p class="space">
? ? <input type="submit" value="登錄" class="login" style="cursor:pointer; ">
? ? </p>
? ? </form>
? ? </div>
? ? </div>
? </body>
</html>
dologin.jsp
<%@
?page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
?String username="";
?String password="";
?request.setCharacterEncoding("utf-8");
?
?username=request.getParameter("username");
?password=request.getParameter("password");
?//username=request.getAttribute("username").toString();
?//password=request.getAttribute("password").toString();
?
?//如果用戶名和密碼都等于admin,則登錄成功
?if("abc".equals(username)&&"12345".equals(password))
?{
? request.getRequestDispatcher("login_success.jsp").forward(request,response);
?
?}
?else
?{
? response.sendRedirect("login_failure.jsp");
?}
%>
login_success.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? <head>
? ? <base href="<%=basePath%>">
? ??
? ? <title>My JSP 'login.jsp' starting page</title>
? ??
<%--
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"> ? ?
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
--%>
<link type="text/css" href="css/login.css" rel="stylesheet"/>
<link type="text/css" href="css/smoothness/jquery-ui-1.7.2.custom.html" rel=""/>
<script type="text/javascript" src="js/jquery 1.3.2.min.js"></script>
<script type="text/javascript" src="js/easyTooltip.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
? </head>
??
? <body>
? ? <div id="container">
? ? <div class="logo">
? ? <a href="#"><img src="assets/logo.png"></a>
? ? </div>
? ? <div id="box">
? ? 歡迎您XXX,登錄成功!
? ? <%--<font color="red"> --%>
? ? </div>
? ? </div>
? </body>
</html>
login_failure.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
? <head>
? ? <base href="<%=basePath%>">
? ??
? ? <title>My JSP 'login.jsp' starting page</title>
? ??
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"> ? ?
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
? </head>
??
? <body>
? ? <div id="container">
? ? <div class="logo">
? ? <a href="#"><img src="assets/logo.png"></a>
? ? </div>
? ? <div id="box">
? ? 登錄失??!請檢查用戶名或者密碼!<br>
? ? <a href="login.jsp">返回登錄</a>
? ?
? ? </div>
? ? </div>
? </body>
</html>
2016-09-09
你的input的username寫錯了 ? 不是urename
2016-09-09
是不是不輸用戶名就會報錯?記得加驗證。
2016-09-03
為何不out.write一下你獲取到的username和password呢