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

JSP数据库帐号密码验证
哪为老哥帮帮小弟~!!代码如下~!怎么才能实现功能啊?
<%@   page   contentType= "text/html;   charset=GB18030 "   %>
<%@page   language= "java "   %>
<%@page   import= "java.sql.* "   %>
<%!
  Connection   con;
    Statement   stat;
    ResultSet   rs;
public   void   Conn(){

    try   {
        Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
        con   =DriverManager.getConnection( "jdbc:odbc:sy ", "sa ", "liming020412 ");
        stat=con.createStatement();
    }
    catch   (Exception   ex)   {
        System.out.println( "数据库连接失败~!!! ");
    }
}
%>
<%
String   sql= "select   *   from   login   where   name= ' "+name+ " '   and   pwd= ' "+pwd+ " ' ";
%>
<%!
public   boolean   login(String   sql){
    try   {
        rs=stat.executeQuery(sql);
        if(rs.next()){
            return   true;
        }
    }
    catch   (Exception   ex)   {
        System.out.println( "登录失败~! ");
    }
    return   false;
}
%>
<html>
<head>
<title>
ConnDemo
</title>
</head>
<body   bgcolor= "#ffffff ">
    <%   %>
<form   method= "post "   action= "Conninfo.jsp "   onsubmit= "return   login() ">
<p> <input   type= "Text "   name= "name "   value= " "   size= "20 "   maxlength= "18 "> </p>
<p> <input   type= "password "   name= "pwd "   value= " "   size= "20 "   maxlength= "18 "> </p>
<p> <input   type= "submit "   name= "Submit "   value= "Submit "> </p>
<input   type= "reset "   value= "Reset ">
</form>
</body>
</html>


------解决方案--------------------
判断用户名,密码最好放javabean里~~~~
charset=GB18030???没用过这个,一般都是charset=UTF-8

在Conninfo.jsp中加上
<%
String name = request.getParameter( "name ");
String pwd = request.getParameter( "pwd ");
%>
再看数据库是否存在此用户名,密码