<%@ page contentType="text/html; charset=gb2312" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><LINK href="hellking.css" type=text/css rel=stylesheet><body>
 <%
   boolean isLog=false;
  // out.println(session.getAttribute("isLog"));
  try
  {
   isLog=((String)session.getAttribute("isLog")).equals("1");
  }
  catch(Exception e)
  {
    //out.println(e);
  }
%>
<table width="842" align=center cellpadding=3 cellspacing=1 class=tableborder1>
    <tr>
    <td width="832" class=tablebody2>::
    <a href="index.jsp" target="_top">首页</a>
    <a href="index.jsp" target="_top">邮件</a>
    <a href="shop/searchForm.html" target="mainFrame">商品搜索</a>
    <a href="/jspdev/servlet/forumservlet?jumpPage=1" target="mainFrame">论坛</a>
    <% 
      if(isLog)
       {
         if(((Integer)session.getAttribute("userType")).equals(new Integer(1)))
         {
         %>
         <a href="index.jsp"  target="_top">个人信息</a>
         <%}
         else
         {
         %>
         <a href="manage/index.jsp" target="_new">系统管理</a>
         <%
         }
        %> 
      <a href="logout.jsp"  target="_top">注销</a><%}%>::
    </td> </tr> <tr>
    <td width="832" class=tablebody2> 
    <%
   // out.println(isLog);
   if(isLog)
  {
   %>
    欢迎光临!<%=session.getAttribute("name")%>,您是第<%=session.getAttribute("userLogCount")%>次登录,您上次登录的时间是:<%=session.getAttribute("userLastLogTime")%>
    <%
    }//if
    else
    {
    %>
    
      <form name="form1" method="post" action="login.jsp">
        &nbsp;&nbsp;&nbsp; 用户名 
        <input type="text" name="userId" size="15" style="BORDER-RIGHT: #ffffff 1px groove; BORDER-TOP: #ffffff 1px groove; FONT: 12px Verdana,Geneva,sans-serif; BORDER-LEFT: #ffffff 1px groove; WIDTH: 100px; COLOR: #000000; BORDER-BOTTOM: #ffffff 1px groove; HEIGHT: 18px; BACKGROUND-COLOR: #DFF1F9">
         密码 
        <input type="password" name="password" size="15" style="BORDER-RIGHT: #ffffff 1px groove; BORDER-TOP: #ffffff 1px groove; FONT: 12px Verdana,Geneva,sans-serif; BORDER-LEFT: #ffffff 1px groove; WIDTH: 100px; COLOR: #000000; BORDER-BOTTOM: #ffffff 1px groove; HEIGHT: 18px; BACKGROUND-COLOR: #DFF1F9">
        <input type="submit" name="Submit" value="确定" style="height:20; font:9pt; BORDER-BOTTOM: #cccccc 1px groove; BORDER-RIGHT: #cccccc 1px groove; BACKGROUND-COLOR: #eeeeee">
  </form> 
  <%
   }//else
   %>   
    </td>
  </tr>
  </table>
</body>
</html>
这是title.jsp
<%@ include file="include.inc"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
//获得请求的参数。
String id=request.getParameter("userId");
String psw=request.getParameter("password");
//连接数据库
Class.forName(CLASSFORNAME);
Connection con = DriverManager.getConnection(SERVANDDB,USER,PWD);
Statement statement=con.createStatement();
String isCorrect="select * from user_info where userId='" + id + "' and password='" + psw + "'";
ResultSet result=statement.executeQuery(isCorrect);
 session.setAttribute("isLog",new String("0"));if(!result.next())
{
response.sendRedirect("index.jsp");//账号或密码错误,转入错误页面
result.close();
statement.close();
con.close();
}
 //如果查询后有记录,说明登录验证成功。
else
{
      //保存登录信息到session对象中。
  session.setAttribute("name",result.getString("name"));
  session.setAttribute("id",result.getString("userId"));  
  session.setAttribute("email",result.getString("email"));
  session.setAttribute("fav",result.getString("fanvcategory"));
  session.setAttribute("userType",new Integer(result.getInt("userType")));   
  System.out.println(session.getAttribute("userType")); 
  session.setAttribute("isLog",new String("1"));
  int count=result.getInt("userLogCount");
  session.setAttribute("userLogCount",new Integer(count));
  count++;
  session.setAttribute("userLastLogTime",result.getString("userLastLogTime"));  
  java.util.Date time1=new java.util.Date();//获得系统当前时间
      String sqltime=new Timestamp(time1.getTime()).toString();//将当前时间转换成sql server可以识别的对象      
 //更新登录信息。
  statement.execute("update user_info set userLogCount="+count+",userLastLogTime='"+sqltime+"' where userId='" + id +"'");
   //关闭数据库连接相关的资源。
  statement.close();
  con.close(); 
  //把页面派发到目的
  response.sendRedirect("index.jsp");
}
%>
这是login.jsp
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="com.microsoft.jdbc.sqlserver.SQLServerDriver"%>
<%@ page import="java.lang.*"%>
<%@ page contentType="text/html; charset=gb2312" %><% 
   request.setCharacterEncoding("gb2312");
   String CLASSFORNAME="com.microsoft.jdbc.sqlserver.SQLServerDriver";
   String SERVANDDB="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=jspdev";
   String USER="bn";
   String PWD="bn";   
%>
这是include.inc