我的代码出现sql rs conn cannot be resolved。别人写得 我新手,。 请问怎么解决
<%@pageimport="java.sql.*"%><%@pagelanguage="java"import="java.util.*"pageEncoding="g...
<%@page import="java.sql.*" %>
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
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 'Enter.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">
</head>
<body>
<%
String username = request.getParameter("username");//参数传递,用户名
String password = request.getParameter("password");//参数传递,密码
PreparedStatement pstmt = null;// 数据库表达式
sql = "select * from Student where username = ? and password= ?";
// SQL语句
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, username);
pstmt.setString(2, password);
rs = pstmt.executeQuery();
if (rs.next()) {//
request.getSession(true);//创建session
//保存登录用户到session中
session.putValue("username", username);
session.putValue("password", password);
session.putValue("userIP", request.getRemoteAddr());
session.putValue("enter", "true");
//登录成功主题页面
response.sendRedirect("MainForm.jsp");
} else
response.sendRedirect("login.html");//登陆失败转向登录页面
%>
</body>
</html> 展开
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
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 'Enter.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">
</head>
<body>
<%
String username = request.getParameter("username");//参数传递,用户名
String password = request.getParameter("password");//参数传递,密码
PreparedStatement pstmt = null;// 数据库表达式
sql = "select * from Student where username = ? and password= ?";
// SQL语句
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, username);
pstmt.setString(2, password);
rs = pstmt.executeQuery();
if (rs.next()) {//
request.getSession(true);//创建session
//保存登录用户到session中
session.putValue("username", username);
session.putValue("password", password);
session.putValue("userIP", request.getRemoteAddr());
session.putValue("enter", "true");
//登录成功主题页面
response.sendRedirect("MainForm.jsp");
} else
response.sendRedirect("login.html");//登陆失败转向登录页面
%>
</body>
</html> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询