jsp页面空指针 5
<%@pageimport="java.sql.*"%><%@pagecontentType="text/html"pageEncoding="UTF-8"%><html...
<%@ page import="java.sql.*"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<title>数据处理页面</title>
<meta http-equiv="Content-type" content="text/html" charset=UTF-8>
</head>
<body bgcolor="cccfff">
<%
String userName = request.getParameter("userName");
byte b1[] = userName.getBytes("ISO-8859-1");
userName = new String(b1, "UTF-8");
String password = request.getParameter("password");
byte b2[] = password.getBytes("ISO-8859-1");
password = new String(b2, "UTF-8");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
if (userName.equals("")) {
response.sendRedirect("login.jsp");
}
try {
String url = "jdbc:odbc:ch06";
String user = "sa";
String password1 = "root";
conn = DriverManager.getConnection(url, user, password1);
stmt = conn.createStatement();
String sql = "select * from user where userName='" + userName
+ "'";
rs = stmt.executeQuery(sql);
if (rs.next()) {
String sql1 = "select * from user where password='"
+ password + "'";
rs = stmt.executeQuery(sql1);
if (rs.next()) {
response.sendRedirect("index.jsp");
} else {
response.sendRedirect("login.jsp");
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
rs.close();
stmt.close();
conn.close();
}
%>
</body>
</html> 展开
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<title>数据处理页面</title>
<meta http-equiv="Content-type" content="text/html" charset=UTF-8>
</head>
<body bgcolor="cccfff">
<%
String userName = request.getParameter("userName");
byte b1[] = userName.getBytes("ISO-8859-1");
userName = new String(b1, "UTF-8");
String password = request.getParameter("password");
byte b2[] = password.getBytes("ISO-8859-1");
password = new String(b2, "UTF-8");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
if (userName.equals("")) {
response.sendRedirect("login.jsp");
}
try {
String url = "jdbc:odbc:ch06";
String user = "sa";
String password1 = "root";
conn = DriverManager.getConnection(url, user, password1);
stmt = conn.createStatement();
String sql = "select * from user where userName='" + userName
+ "'";
rs = stmt.executeQuery(sql);
if (rs.next()) {
String sql1 = "select * from user where password='"
+ password + "'";
rs = stmt.executeQuery(sql1);
if (rs.next()) {
response.sendRedirect("index.jsp");
} else {
response.sendRedirect("login.jsp");
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
rs.close();
stmt.close();
conn.close();
}
%>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询