<%
String user,pwd;
user="wjz";
pwd="wjz";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:bookstore");
Statement smt = conn.createStatement();
//ResultSet rs = smt.executeQuery("select name,pwd from user where name='" + user + "',pwd='" + pwd + "'");
ResultSet rs = smt.executeQuery("select * from user where name='"+user+"'");
System.out.println("hello");
out.println(rs.getString("name"));
%>
为什么打印不出来,表中user中rs对应指针的name值来???
String user,pwd;
user="wjz";
pwd="wjz";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:bookstore");
Statement smt = conn.createStatement();
//ResultSet rs = smt.executeQuery("select name,pwd from user where name='" + user + "',pwd='" + pwd + "'");
ResultSet rs = smt.executeQuery("select * from user where name='"+user+"'");
System.out.println("hello");
out.println(rs.getString("name"));
%>
为什么打印不出来,表中user中rs对应指针的name值来???
{
out.println(rs.getString("name"));
}
String user,pwd;
user="wjz";
pwd="wjz";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:bookstore");
Statement smt = conn.createStatement();
//ResultSet rs = smt.executeQuery("select name,pwd from user where name='" + user + "',pwd='" + pwd + "'");
ResultSet rs = smt.executeQuery("select * from user where name='"+user+"'");
while(rs.next())
{
System.out.println("hello");
out.println(rs.getString("name"));
}
%>
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp2
</title>
</head>
<body bgcolor="#ffffff">
<%
String user,pwd;
user=request.getParameter("username");
pwd=request.getParameter("password");
%>
<%try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:bookstore","","");
Statement stat=conn.createStatement();
//stat.executeUpdate("insert into values'"+user+"','"+pwd+"'");
ResultSet rs=stat.executeQuery("select * from userinfo where username='"+user+"'");
if (user.equals(rs.toString()))
{
%>
<jsp:forward page="jsp3.jsp"/>
<%}else{%>
<jsp:forward page="jsp4.jsp"/>
<%}
}catch(Exception ex)
{
ex.getMessage();
}
%>
</body>
</html>
讲不通
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp2
</title>
</head>
<body bgcolor="#ffffff">
<%
String user,pwd;
user=request.getParameter("username");
pwd=request.getParameter("password");
%>
<%try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:bookstore","","");
Statement stat=conn.createStatement();
//stat.executeUpdate("insert into values'"+user+"','"+pwd+"'");
ResultSet rs=stat.executeQuery("select * from userinfo where username='"+user+"'");
if (user.equals(rs.getString("username")))
{
%>
<jsp:forward page="jsp3.jsp"/>
<%}else{%>
<jsp:forward page="jsp4.jsp"/>
<%}
}catch(Exception ex)
{
ex.getMessage();
}
%>
</body>
</html>
ResultSet rs=stat.executeQuery("select * from userinfo where username='"+user+"'");
rs.next();加上这个,要让rs去读记录
if (user.equals(rs.getString("username")))
{
%>
<jsp:forward page="jsp3.jsp"/>
<%}else{%>
<jsp:forward page="jsp4.jsp"/>
<%}
}catch(Exception ex)
{
ex.getMessage();
}
%>
</body>
</html>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp2
</title>
</head>
<body bgcolor="#ffffff">
<%
String user,pwd;
user=request.getParameter("username");
pwd=request.getParameter("password");
%>
<%try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:bookstore","","");
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from userinfo where username='"+user+"'and password='"+pwd+"'");
rs.next();
if ((user.equals(rs.getString("username")))&&((pwd.equals(rs.getString("password")))))
{
%>
<jsp:forward page="jsp3.jsp"/>
<%}else{%>
<jsp:forward page="jsp4.jsp"/>
<%}
}catch(Exception ex)
{
ex.getMessage();
}
%>
</body>
</html>
<% String path = request.getContextPath(); %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.sql.*" %>
<%@ page import = "java.text.*" %>
<%@ page language ="java" %>
<%! int flag = 0; %>
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
con = DriverManager.getConnection("jdbc:odbc:kiki","","");
Statement stmt ;
String actNumber,actNo,password,pwd;
stmt = con.createStatement();
actNumber = (String)request.getParameter("txtActNumber");
password = (String)request.getParameter("txtUsrPwd");
password=password.trim();
actNumber=actNumber.trim();
String strQuery1 ="select * from admin where Account_ID='" + actNumber +"' ";
System.out.println("strQuery1======="+strQuery1);
ResultSet rs;
rs = stmt.executeQuery(strQuery1);
while(rs.next())
{ session.setAttribute("login",1);
actNo=(String)rs.getString("Register_ID");
pwd=(String)rs.getString("Password");
actNo=actNo.trim();
pwd=pwd.trim();
if((pwd.equals(password))&&(actNumber.length() !=0)&&(pwd.length() !=0)&&(actNo.length() !=0))
{
flag = 1;
%>
<jsp:forward page="/home_page.jsp"/>
<%
}
}
}
//session.setAttribute("login",1);
catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("try.....catch.....end");
%>
<html>
<head>
<title>管理员登录</title>
</head>
<body>
<form name="form" method="post"" action="<%=path%>/login_page.jsp" target="_blank">
<P><b></b></P>
<table width="380" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CC9966">
<tr align="center">
<td colspan="2"><b><font color="#FF0000" size="4">输入的用户名或密码有误,请重新登录</font></b></td>
</tr>
<tr>
<td width="153" align="center" bgcolor="#ECE9D8"><font>用户ID:</font></td>
<td width="221" align="left"><input type="text"name="txtActNumber"size="20"></td>
</tr>
<tr>
<td align="center" bgcolor="#ECE9D8"><font>密 码:</font></td>
<td align="left"><input type="password" name="txtUsrPwd" size="20"></td>
</tr>
<tr>
<td align="right"><input type="submit"value="登录"name="login" onClick="javascript:return check()"></td>
<td align="left"><input type="reset"value="重置"name="cancel"></td>
</tr>
</table>
<p> </P>
</form>
</body>
<script language="JavaScript">
function check()
{
if((((form.txtActNumber.value).length==0)||((form.txtUsrPwd.value).length==0)))
{
alert("用户ID或密码不能为空");
return false;
}
else
{
return true;
}
}
</script>
</html>
while(rs.next()){
if ((user.equals(rs.getString("username")))&&((pwd.equals(rs.getString("password")))))
{
%>
<jsp:forward page="jsp3.jsp"/>
<%
}}}
%>
<jsp:forward page="jsp4.jsp"/>