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

session记录的问题,大家帮帮忙
本人原意是成功登陆以后就把登陆的人次数加1,但是我发现就算已经登陆的人再一次登陆还是可以登陆的,如何才能禁止他只能登陆一次.我用session无法做到,大家帮帮我用session怎么搞.
源代码:
<%@   page   contentType= "text/html;charset=GB2312 "   %>
<%@   page   import= "java.sql.* "   %>
<%@   page   import= "java.util.* "%>
<html>
<link   href= "css/wenzi.css "   rel= "stylesheet "   type= "text/css ">

<body>
<%  
String   driverName= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String   dbURL= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=login ";
String   userName= "sa ";
String   passWord= " ";
Connection   con=null;
Statement   sql=null;
ResultSet   rs=null;
String   Name=request.getParameter( "username ");
byte[]   b=Name.getBytes( "ISO-8859-1 ");
Name=new   String(b);
String   PassWord=request.getParameter( "password ");
byte[]   b1=PassWord.getBytes( "ISO-8859-1 ");
PassWord=new   String(b1);
int   sum=0;
String   str=null;
try
{
Class.forName(driverName);
}
catch(ClassNotFoundException   e)
{
out.print(e.toString());
}
try
{
con=DriverManager.getConnection(dbURL,userName,passWord);
sql=con.createStatement();
String   execute= "select   *   from   login   where   UserName= ' "+Name+ " '   and   PassWord= "+PassWord+ " ";
rs=sql.executeQuery(execute);
if(rs.next())
{
sum=rs.getInt( "count ");
sum++;

%>
<table   width= "42% "   border= "0 "   align= "center ">
    <tr>  
        <td   class= "wenzi ">
<div   align= "center "> 个人信息 </div> </td>
    </tr>
    <tr>  
        <td   class= "wenzi ">
<div   align= "center "> 登陆成功,你是第 <%=sum%> 次登陆 </div> </td>
    </tr>
    <tr>  
        <td> &nbsp; </td>
    </tr>
</table>
<%
String   execute1= "update   login   set   count= "+sum+ "   where   UserName= "+ " ' "+Name+ " ' ";
sql.executeUpdate(execute1);
}
else
{
out.print( " <font   size=1> 登陆错误 ");
}
con.close();
}
catch(SQLException   e)
{
out.print(e.toString());
}
  %>
</body>
</html>

------解决方案--------------------
怎么还有这么一句话--登陆成功,你是第 <%=sum%> 次登陆?
你不是只想让用户登陆一次的吗?
用户表中还有sum字段,什么意思呢?
---------------------------------
本人原意是成功登陆以后就把登陆的人次数加1,但是我发现就算已经登陆的人再一次登陆还是可以登陆的,如何才能禁止他只能登陆一次.我用session无法做到,大家帮帮我用session怎么搞.
------解决方案-----