登录时,无论输入什么,或者就是空值,点击登录后都是直接输出“用户名或密码错误”想知道如何解决这个问题!!!!!
# **index.jsp**
```<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<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">
<title>大学生宿舍管理系统</title>
<style type="text/css">
body {
width:1300px;
background-image: url("imgs/222.jpg");;
background-repeat: no-repeat;
background-size:100% 100%;
background-attachment:fixed;
}
#login_frame {
width: 400px;
height: 260px;
padding: 13px;
position: fixed;
left: 65%;
top: 75%;
margin-bottom: 70%;
margin-left: -100px;
margin-top: -200px;
background-color: rgba(240, 255, 255, 0.25);
border-radius: 10px;
text-align: center;
}
.text_class {
width: 180px;
height: 26px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border: 0;
}
#btn_login {
font-size: 14px;
font-family: 宋体;
width: 100px;
height: 28px;
line-height: 28px;
text-align: center;
color: white;
background-color: #3BD9FF;
border-radius: 6px;
border: 0;
float: 160px;
}
#btn_regis {
font-size: 14px;
font-family: 宋体;
width: 100px;
height: 28px;
line-height: 28px;
text-align: center;
color: white;
background-color: #3BD9FF;
border-radius: 6px;
border: 0;
float: 160px;
#forget_pwd:hover {
color: blue;
text-decoration: underline;
}
#login_control {
padding: 0 28px;
}
</style>
<script type="text/javascript">
function jianyanIndex()
{
var name = document.frmIndex.username.value;
var pwd = document.frmIndex.psaaword.value;
if(name=="")
{
alert("请输入用户名!");
return false;
}
if(pwd=="")
{
alert("请输入密码!");
return false;
}
}
</script>
</head>
<body>
<div id ="login_frame">
<form method ="post" action="IndexServer.jsp" name="frmIndex">
<div>
<p><input type="text" id="username" placeholder="请输入用户名" class="text_class"></p>
</div>
<div>
<p><input type="password" id="password" placeholder="请输入密码" class="text_class"></p>
</div>
<div id="login_control">
<input type="submit" id="btn_login" value="登录" onclick="jianyanIndex(;)" />
<input type="button" id="btn_regis" value="注册" onclick="window.location.href='register.jsp'"/>
</div>
</form>
</div>
</body>
</html>
IndexServer.jsp****
<%@ page language="java" import="java.sql.*" 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>登录检验</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">
</head>
<body>
<br>
<%
request.setCharacterEncoding("utf-8");
String users=request.getParameter("username");
String pass=request.getParameter("password");
%>
<%
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/success?serverTimezone=GMT";
String use = "root";
String Password = "fxnbdr15820!";
Class.forName(driver);
Connection conn= DriverManager.getConnection(url,use,Password);
String sql="select * from student where username='"+users+"'and password='"+ pass +"'";
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{
session.setAttribute("uname","users");
out.print("登录成功!!!!");
}else
{
out.print("用户名不存在或密码错误!!!!");
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>