当前位置: 代码迷 >> Java Web开发 >> jsp中javabean的有关问题
  详细解决方案

jsp中javabean的有关问题

热度:102   发布时间:2016-04-17 12:48:54.0
jsp中javabean的问题。
这是一个通过数据库验证用户名及登录密码的程序。有表单直接提交数据由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 "> &nbsp;&nbsp;&nbsp;&nbsp; <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;
}

}
我验证过了表单传递的数据没有传过去 不知道哪错了?大家帮忙看下啊。


------解决方案--------------------
你用的控件对么?我忘记了!呜呜!

------解决方案--------------------
  相关解决方案