bean内容:
package test;
import java.sql.*;
public class Login
{
String users="";
String usertype="";
String password="";
String success="false",
message="";
public Login()
{
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
}
public void setUsertype(String No)
{
usertype=No;
}
public String getUsertype()
{
return usertype;
}
public void setUsers(String name)
{
users=name;
}
public String getUsers()
{
return users;
}
public void setPassword(String number)
{
password=number;
}
public String getPassword()
{
return password;
}
public String getSuccess()
{
return success;
}
public String getMessage()
{
Connection con;
Statement sql;
ResultSet rs;
try{
con=DriverManager.getConnection("jdbc:odbc:sun","sa","");
sql=con.createStatement();
String condition="select * from user WHERE users="+"'"+users+"'";
rs=sql.executeQuery(condition);
int rowcount=0;
String ps="";
String bs="";
while(rs.next())
{
rowcount++;
users=rs.getString("users");
ps=rs.getString("password");
bs=rs.getString("usertype");
}
if((rowcount==1)&&(password.equals(ps))&&(usertype.equals(bs)))
{
message="ok";
success="ok";
}
else
{
message="输入的用户名或密码不正确";
try{byte d[]=message.getBytes("ISO-8859-1");
message=new String(d);
return message;
}
catch(Exception e1)
{ }
success="false";
}
con.close();
return message;
}
catch(SQLException e)
{
message="输入的用户名或密码不正确";
try{byte d[]=message.getBytes("ISO-8859-1");
message=new String(d);
return message;
}
catch(Exception e1)
{ }
success="false";
return message;
}
}
}
测试程序:<%@ page import="test.Login"%>
<jsp:useBean id="g" class="test.Login" scope="page">
</jsp:useBean>
<jsp:setProperty name="g" property="usertype" value="s" />
<jsp:setProperty name="g" property="users" value="袁柏军" />
<jsp:setProperty name="g" property="password" value="123456789" />
<% String message=g.getMessage();
out.print(message);
%>
打印出来 12个? 为什么啊?
package test;
import java.sql.*;
public class Login
{
String users="";
String usertype="";
String password="";
String success="false",
message="";
public Login()
{
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
}
public void setUsertype(String No)
{
usertype=No;
}
public String getUsertype()
{
return usertype;
}
public void setUsers(String name)
{
users=name;
}
public String getUsers()
{
return users;
}
public void setPassword(String number)
{
password=number;
}
public String getPassword()
{
return password;
}
public String getSuccess()
{
return success;
}
public String getMessage()
{
Connection con;
Statement sql;
ResultSet rs;
try{
con=DriverManager.getConnection("jdbc:odbc:sun","sa","");
sql=con.createStatement();
String condition="select * from user WHERE users="+"'"+users+"'";
rs=sql.executeQuery(condition);
int rowcount=0;
String ps="";
String bs="";
while(rs.next())
{
rowcount++;
users=rs.getString("users");
ps=rs.getString("password");
bs=rs.getString("usertype");
}
if((rowcount==1)&&(password.equals(ps))&&(usertype.equals(bs)))
{
message="ok";
success="ok";
}
else
{
message="输入的用户名或密码不正确";
try{byte d[]=message.getBytes("ISO-8859-1");
message=new String(d);
return message;
}
catch(Exception e1)
{ }
success="false";
}
con.close();
return message;
}
catch(SQLException e)
{
message="输入的用户名或密码不正确";
try{byte d[]=message.getBytes("ISO-8859-1");
message=new String(d);
return message;
}
catch(Exception e1)
{ }
success="false";
return message;
}
}
}
测试程序:<%@ page import="test.Login"%>
<jsp:useBean id="g" class="test.Login" scope="page">
</jsp:useBean>
<jsp:setProperty name="g" property="usertype" value="s" />
<jsp:setProperty name="g" property="users" value="袁柏军" />
<jsp:setProperty name="g" property="password" value="123456789" />
<% String message=g.getMessage();
out.print(message);
%>
打印出来 12个? 为什么啊?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货