这是一个通过数据库验证用户名及登录密码的程序。有表单直接提交数据由javabean对数据进行验证。
<%@ page contentType= "text/html; charset=utf-8 " language= "java " import= "java.sql.* " errorPage= " "%>
<%@ page import= "data.testdata " %>
<jsp:useBean id= "login " scope= "page " class= "data.testdata ">
</jsp:useBean>
<jsp:setProperty name= "login " property= "* "/>
<html>
<head>
<title> Untitled Document </title>
</head>
<body>
<form action= " " method= "post " name= "form1 ">
<table align= "center " >
<tr> <th> 学号 <input type= "text " name= "num " /> </th> </tr>
<tr> <th> 密码 <input type= "text " name= "code "/> </th> </tr>
<tr> <th> <input type= "submit " name= "B1 "> <input type= "reset " name= "B2 "> </th> </tr>
</table>
</form>
<%=login.check()%>
</body>
</html>
以下是java程序。
package data;
import java.sql.*;
public class testdata
{
String num;
String code;
Connection con;
Statement stmt;
ResultSet rs;
public testdata()
{
try
{
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
} catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
String url= "jdbc:odbc:atmdatabase ";
Connection con = null;
try
{
con = DriverManager.getConnection(url, " ", " ");
} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
String sql= "select * from atm where cardID= ' "+num+ " ' and code= ' "+code+ " ' ";
Statement stmt;
try
{
stmt = con.createStatement();
rs=stmt.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String check()
{
String ok= "ooxx ";
try
{
if(rs.next())
{
return code;
}
else
{
return num;
}
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return ok;
}
}
我验证过了表单传递的数据没有传过去 不知道哪错了?大家帮忙看下啊。
------解决方案--------------------
你用的控件对么?我忘记了!呜呜!
------解决方案--------------------