日期:2014-05-18  浏览次数:20694 次

能提供一个jsp+bean+mysql的用户登录,退出源程序吗?感激不尽!
能提供一个jsp+bean+mysql的用户登录,退出源程序吗?感激不尽!

------解决方案--------------------
package a_nuo.beans;
import java.sql.*;
public class Login {
String logname,
password,
success= "false ",
message= " ";
Connection con;
Statement sql;
ResultSet rs;
public Login(){
try{
Class.forName( "com.microsoft.sqlserver.SQLServerDriver ");
}catch(ClassNotFoundException e){

}
}
public String getLogname() {
return logname;
}
public void setLogname(String logname) {
this.logname = logname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getMessage() {
try{
con=DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=TestDB ", "sa ", "密码 ");
sql=con.createStatement();
String condition= "select * from member where logname= "+ " ' "+logname+ " ' ";
rs=sql.executeQuery(condition);
int rowcount=0;
String ps=null;
while(rs.next())
{
rowcount++;
logname=rs.getString( "logname ");
ps=rs.getString( "password ");
}
if((rowcount==1)&&(password.equals(ps)))
{
message= "ok ";
success= "ok ";
}
else {
message= "输入的用户名或密码不正确 ";
success= "false ";
}
con.close();
return message;

}catch(SQLException e){
message= "输入的用户名或密码不正确(异常) ";
success= "false ";
return message;
}
}
public String getSuccess() {
return success;
}
}


<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= " " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 登陆页面 </title>
</head>
<%!
public String codeString(String s)
{
String str=s;
try{
byte[] b=str.getBytes( "ISO-8859-1 ");
str=new String(b);
return str;
}catch(Exception e)
{return str;}
}
%>
<body>
<%@ include file= "head.txt " %>
<P> 输入用户名和密码:
<% String str=response.encodeRedirectURL( "login3.jsp ");%>
<form action= " <%=str%> " method= "post " >
<br /> 登录名称 <input type= "text " name= "logname " />
<br /> 输入密码 <input type= "password " name= "password " />
<br /> <input type= "submit " name= "g " value= "提交 " />
</form>
<jsp:useBean id= "lo