与mysql,判断能否登录帐号密码,能登录则转向index_stu.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>My JSP 'check.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><%
String driverName="com.mysql.jdbc.Driver";
String dbName="MyLogin";
String userName="root";
String userPwd="lovezjl";
String url1="jdbc:mysql://localhost:3306/MyLogin";
String url2="?user=root&password=lovezjl";
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
Class.forName(driverName);
Connection conn=DriverManager.getConnection(url);
String Cname=request.getParameter("zzname");
String Cpassword=request.getParameter("password");
String Cn="select num from student_info2 where usename='"+Cname+"' and password='"+Cpassword+"'";
Statement stmt=conn.createStatement();
ResultSet rs11=stmt.executeQuery(Cn);
if(rs11.first()){%><jsp:forward page="index_stu.html"/><%}
else{%>
<jsp:forward page="login_fail.jsp"/>
<%} %>
</body>
</html>