Java+Servlet+JSP
采用MVC模式(Model+View+Controller)
功能:
项目的主要模块:注册模块,登陆模块,留言列表模块,留言模块,留言详情模块。
注册模块:实现用户注册,将新注册用户数据(用户名和密码)写入数据库,并能识别该用户是否已注册,以及判断注册时密码和确认密码是否一致。
登陆模块:实现用户登陆,能够判断该用户是否已注册,用户名密码是否为空以及密码填写是否正确。
留言列表模块:展示是数据库中留言信息(包括留言数,留言标题,留言内容,留言时间以及用户ID),点击留言标题可以跳转到详细的留言页面。
留言模块:留言模块包含留言标题和留言内容,点击提交之后会将数据存在数据库中,并展示于留言列表页面。
留言详情模块:展示某项留言的详细信息,以及展示该留言下的评论。以及评论该留言。
整体框架
View:\登陆界面\注册界面\留言列表界面\留言细节界面(评论)\留言界面
1.login.jsp文件
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新浪微博</title>
<style type="text/css">
body {
background-color: white;
background-size: 100% 100%;
background-repeat:no-repeat;
background-attachment:fixed
}
html {
height:100%;
weight:100%;
}
label{
color:white;
font-weight:bolder;
}
.center-in-center{
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.col{
color:white;
font-weight:bolder;
}
</style>
</head>
<body background="pictures/言叶之庭8.png">
<div align="center" class="center-in-center">
<h1 class ="col"> 登陆入口</h1>
<form action="LoginServlet" method = "post">
<input type="hidden" name="action" value="login">
<label>用户名:</label>
<input type="text" name="username" style=width:150px;height:20px; ><br>
<label>密码:</label>
<input type="password" name="password" style=width:150px;height:20px; ><br>
<input type="submit" name="login" value="登陆" style=width:150px;height:20px;><br>
<input type="reset" name="reset" value="重置" style=width:150px;height:20px;><br>
<button type="submit" formaction="register.jsp" style=width:150px;height:20px;>注册</button>
</form>
<p class="col">${message}</p>
</div>
</body>
</html>
2.register.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>新浪微博</title>
<style type="text/css">
body {
background-color: white;
background-size: 100% 100%;
background-repeat:no-repeat;
background-attachment:fixed
}
html {
height:100%;
weight:100%;
}
label{
color:white;
font-weight:bolder;
}
h1{
color:white;
}
.center-in-center{
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
-o-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
.col{
color:white;
font-weight:bolder;
}
</style>
</head>
<body background="pictures/言叶之庭8.png">
<div align="center" class="center-in-center">
<h1 align="center"> 请完善您的相关信息:</h1>
<form action="RegistServlet" method="post">
<input type="hidden" name="action" value="regist"><br>
<label>用户名:</label>
<input type="text" name="username" required><br>
<label>密码:</label>
<input type="text" name="password" required><br>
<label>确认密码:</label>
<input type="password" name="password2" required>
<p class="col">${message}</p>
<input type="submit" name="regist" value="注册" style=width:75px;>
<input type="reset" value="重置" style=width:75px;>
</form>
</div>
</body>
</html>
3.MessageList.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*,javaBean.Message"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>留言板系统</title>
<style type="text/css">
body {
background-color: white;
background-size: 100% 100%;
background-repeat:no-repeat;
background-attachment:fixed
}
html {
height:100%;
weight:100%;
}
</style>
</head>
<body background="pictures/言叶之庭4.jpeg">
<div align="center">
<br>
<h1>欢迎来到留言系统</h1>
<table width="800" border="1" cellpadding="5">
<%
ArrayList mL=(ArrayList)request.getAttribute("MessageList");
%>
<tr>
<th>留言数</th>
<th>标题</th>
<th>留言内容</th>
<th>用户ID</th>
</tr>
<% if (mL != null){
for (int i = 0; i < mL.size(); ++i ){
Message message = (Message)mL.get(i);%>
<tr>
<td><%= message.getmid() %></td>
<td><a href="MessageDetail.jsp?mid=<%= message.getmid() %>"><%= message.gettitle() %></td>
<td><%= message.getcontext() %></td>
<td><%= message.getuserid() %></td>
</tr>
<% } } %>
</table>
<h2><a href="LeaveMessage.jsp">我要留言</a> </h2>
</div>
</body>
</html>
4.LeaveMessage.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>新浪微博</title>
<style type="text/css">
body {
background-color: white;
background-size: 100% 100%;
background-repeat:no-repeat;