首先登录验证
1、index.jsp(首页页面)
<%@ page language="java" pageEncoding="GBK" import="java.util.*,entity.*,dao.*,dao.impl.*" %>
<%
BoardDao boardDao = new BoardDaoImpl();//实例化板块对象
TopicDao topicDao = new TopicDaoImpl();//实例化主题类对象
UserDao userDao = new UserDaoImpl();//用户
Map mapBoard = boardDao.findBoard();//查询板块
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link rel="stylesheet" href="css/index.css" type="text/css">
<title>首页</title>
</head>
<body>
<div id ="apDiv1" align=center>
<div align ="center" class = "STYLE1">校园BBS系统</div>
</div>
<%
if(session.getAttribute("user")==null){
%>
<div class="STYLE4" id="apDiv22" >
您尚未<a href="login1.jsp" target="_blank">登录</a> |
<a href="zhuce.jsp" target="_blank"> 注册a</a>|
<a href="zhuce1.jsp" target="_blank"> 注册b</a>|
<a href="zhuce_to_doReg.jsp" target = "_blank">实名注册</a>
</div>
<%
}else{
User loginUser= (User)session.getAttribute("user");
%>
<div class="h">
您好:<%=loginUser.getUserName() %>
| <a>欢迎第<%=loginUser.getUserId() %>位用户访问</a>
</div>
<a href="manage/doLogout.jsp">登出</a>
<%} %>
<div id="apDiv3" >
<table width="1000" height="503" border="1" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2" align="left" valign="middle"><span class="STYLE4">论坛</span></td>
<td width="5%" class="STYLE4">主题</td>
<td width="45%" class="STYLE4">最后发表</td>
</tr>
<!-- 主板块 -->
<%
List listMainBoard = (List)mapBoard.get(new Integer(0));//..包,强制类型转换成List类型
for(int i=0;i<listMainBoard.size();i++){
Board mainBoard = ((Board)listMainBoard.get(i));//循环取得主板块
%>
<TR class="tr3">
<TD colspan="4"> <%=mainBoard.getBoardName()%> </TD>
</TR>
<!-- 子版块 -->
<%
List listSonBoard = (List)mapBoard.get(new Integer(mainBoard.getBoardId()));
for(int j=0;j<listMainBoard.size();j++){
Board sonBoard =(Board)listSonBoard.get(j);//循环取得主板块
Topic topic = new Topic();
User user= new User();
int boardId = sonBoard.getBoardId();
List listTopic = topicDao.findListTopic(1,boardId);
if(listTopic!= null&&listTopic.size()>0){
topic =(Topic)listTopic.get(0);
user = userDao.findUser(topic.getUserId());
}
%>
<TR class ="tr3">
<TD width="5%"> </TD>
<TH align ="left">
<IMG src= "image/board.jpg" style="height: 50px; width: 60px; "></IMG>
<a href="list.jsp?page=1&boardId=<%=boardId %>"><%=sonBoard.getBoardName() %></a>
</TH>
<TD align ="center"><%=topicDao.findCountTopic(boardId)%></TD>
<TH>
<SPAN>
<!-- 最后发表的内容 -->
<A href="detail.jsp?page=1&boardId=<%=boardId %>&topicId=<%=topic.getTopicId() %>"><%=topic.getTitle()%></A>
</SPAN>
<BR/>
<SPAN><%=user.getUserName() %></SPAN>
<SPAN class="gray">[<%=topic.getPublishTime()%> ]</SPAN>
</TH>
</TR>
<%
}
}
%>
</bable>
</div>
</body>
</html>
2、login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="dao.impl.UserDaoImpl" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="index.css" type="text/css">
<title>登录</title>
<style>
#apDiv2{
position:absolute;
left:1px;
top:51px;
width:100%;
height:25px;
z-index:2;
background-color:#e0f0f9;
}
</style>
<script language="javascript">
function checkInfo(){
var name = document.getElementById("names").value;
var password = document.getElementById("passs").value;
if(name ==""){
alert("请输入账号");
return false;
}else if(password==""){
alert("请输入密码")
return false;
}else
return true;
}
function but(){
if(checkInfo()){
window.location.href="success11.jsp";
}else
return;
}
<script>
function jump(){
window.location.href="http://blog.sina.com.cn/mleavs";
}
</script>
</script>
</head>
<body>
<h2 align="center">校园BBS系统</h2>
<div class="STYLE4" id="apDiv2" >
您尚未<a href="login1.jsp" target="_blank">登录</a> |
<a href="zhuce_to_doReg.jsp" target="_blank"> 注册</a> |
<a href="index3.jsp" target="_blank"> 返回首页>></a>
</div>
<br>
<form method="post" action="manage/doLogin.jsp" class="backForm">
<h2 align="center" style="padding-top: 25px">登录界面</h2><br>
<table align="center">
<tr>
<td>用户名:</td>
<td><input align="center" type="text" name="username" maxlength="10"></td>
</tr>
<tr>
<td>密 码:</td>
<td><input align="center" type="password" name="password"maxlength="10"></td>
</tr>
<tr>
<td> </td>
<td>
<input align="center" type="reset" value="重置">
<input align="center" type="submit" value="登录">
</td>