netbeans连接数据库代码运行出现http500错误
代码无报错<%@pagecontentType="text/html"pageEncoding="UTF-8"import="java.sql.*"import="jav...
代码无报错
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*" import="java.lang.*" %>
<!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>JSP Page</title>
</head>
<body>
<%
String username = request.getParameter("username");
String password = request.getParameter("userpass");
Connection con = null;
Statement st = null;
ResultSet rs = null;
if (username.equals("")) {
response.sendRedirect("index.jsp");
}
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "yamao120");
st = con.createStatement();
String sql = "select*from student where username='" + username+ "'";
rs = st.executeQuery(sql);
if (rs.next()) {
//用户判断密码是否正确
String sql1 = "select*from student where password='" + password + "'";
rs = st.executeQuery(sql1);
if (rs.next()) {
response.sendRedirect("main.jsp");
} else {
response.sendRedirect("index.jsp");
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
rs.close();
st.close();
con.close();
}
%>
</body>
</html>
运行之后是下面这个图 展开
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*" import="java.lang.*" %>
<!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>JSP Page</title>
</head>
<body>
<%
String username = request.getParameter("username");
String password = request.getParameter("userpass");
Connection con = null;
Statement st = null;
ResultSet rs = null;
if (username.equals("")) {
response.sendRedirect("index.jsp");
}
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "yamao120");
st = con.createStatement();
String sql = "select*from student where username='" + username+ "'";
rs = st.executeQuery(sql);
if (rs.next()) {
//用户判断密码是否正确
String sql1 = "select*from student where password='" + password + "'";
rs = st.executeQuery(sql1);
if (rs.next()) {
response.sendRedirect("main.jsp");
} else {
response.sendRedirect("index.jsp");
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
rs.close();
st.close();
con.close();
}
%>
</body>
</html>
运行之后是下面这个图 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询