登陆 页面 yy版
<%@ page language="java" contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<title>Login Test</title>
</head>
<body>
<form method="post">
<input name="userName" /><hr />
<input name="password" /><hr />
<input type="submit" value="提交" />
</form>
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
}catch(Exception e){
out.println(e);
}
%>
<%
String getUser = request.getParameter("userName");
String getPwd = request.getParameter("password");
try{
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/db?user=root&password=pf");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from bg where userName = '"+getUser+"' and userPwd = '"+getPwd+"'");
int n = 0;
while(rs.next()){
n++;
}
if(n>0){
out.println("登陆成功");
}else{
out.println("用户名或密码错误!");
}
}catch(Exception e){
out.println(e);
}
%>
</body>
</html>