《第二个web项目》在线短信平台,实现接收消息,信封根据已读未读动态闭合打开,非法弹框警告等功能
在线短信平台
一、简介
本项目用到的技术有:java、html、css、jsp、servlet、druid、tomcat、filter,使用工具myeclipse2018
已实现的功能有:登陆、注册、页面跳转、弹窗警告、查看短信、回复、删除信息、修改资料、已读未读提示等
二、项目大致的功能关系图
三、登陆层
1.login.jsp
介绍: 登陆界面,接收用户输入的账号密码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>学士后 短消息平台</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%
String msg = (String) request.getAttribute("msg");
if (msg != null && !msg.equals("")) {
%><script type="text/javascript">alert("<%=msg%>")
<%}%>
</script>
</head>
<body>
<div id="loginTitle" class="png"></div>
<div id="loginForm" class="userForm png">
<form method="post" name="loginform" action="/jsp_day2/check/login">
<dl>
<dt>用户名:</dt>
<dd>
<input type="text" name="username" />
</dd>
<dt>密 码:</dt>
<dd>
<input type="password" name="password" />
</dd>
</dl>
<div class="buttons">
<input class="btn-login png" type="submit" name="submit" value=" " /><input
class="btn-reg png" type="button"
onClick="window.location.href='register.jsp'" name="register"
value=" " />
</div>
</form>
</div>
</body>
</html>
2.LoginAction
介绍: 掉用dao层方法验证账号密码是否输入正确
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.UsersDaoImpl;
import entity.Users;
public class LoginAction extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -947788533926255252L;
private static final UsersDaoImpl udi = new UsersDaoImpl();
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String username = req.getParameter("username");
String password = req.getParameter("password");
Users us = udi.queryUsersByUserName(username);
req.setAttribute("login", "yes");
if (us == null || !password.equals(us.getPassword())) {
req.setAttribute("login", "no");
req.setAttribute("msg", "用户名或密码不存在!");
req.getRequestDispatcher("/login.jsp").forward(req, resp);
} else {
req.getSession().setAttribute("name", username);
req.getSession().setAttribute("uid", us.getUsersId());
resp.sendRedirect("/jsp_day2/private/showMsg.jsp");
}
}
}
四、注册层
1.register.jsp
介绍: 注册界面,接收用户输入的信息和Action中判断的结果,如果不合法,出现弹窗提示
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>学士后 在线短信平台</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%
String msg = (String) request.getAttribute("msg");
if (msg != null && !msg.equals("")) {
%><script type="text/javascript">alert("<%=msg%>")
</script>
<%
}
%>
</head>
<body>
<div id="regTitle" class="png"></div>
<div id="regForm" class="userForm png">
<form action="/jsp_day2/check/regist" method="post">
<dl>
<dt>用 户 名:</dt>
<dd>
<input type="text" name="username" />
</dd>
<dt>密 码:</dt>
<dd>
<input type="password" name="password" />
</dd>
<dt>确认密码:</dt>
<dd>
<input type="password" name="affirm" />
</dd>
<dt>邮 箱:</dt>
<dd>
<input type="text" name="email" />
</dd>
</dl>
<div class="buttons">
<input class="btn-reg png" type="submit" name="register" value=" " />
<input class="btn-reset png" type="reset" name="reset" value=" " />
</div>
<div class="goback">
<a href="/jsp_day2/login.jsp" class="png">返回登录页</a>
</div>
</form>
</div>
</body>
</html>
2.RegistAction
介绍: 调用dao层方法,判断注册信息是否合法。如果不合法,将错误信息放入request作用域并转发到注册界面
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.UsersDaoImpl;
import entity.Users;
public class RegistAction extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -9165610699384473172L;
private static final UsersDaoImpl udi = new UsersDaoImpl();
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String username = req.getParameter("username");
String password = req.getParameter("password");
String affirm = req.getParameter("affirm");
String email = req.getParameter("email");
req.getSession().setAttribute("regist", "no");
if (username.equals("")) {
req.setAttribute("msg", "账号不能为空!");
req.getRequestDispatcher("/register.jsp").forward(req, resp);
} else if (password.equals("")) {
req.setAttribute("msg", "密码不能为空!");
req.getRequestDispatcher("/register.jsp").forward(req, resp);
} else if (email.equals("")) {
req.setAttribute("msg", "邮箱号不能为空!");
req.getRequestDispatcher("/register.jsp").forward(req, resp);
} else if (udi.ifExistToUserName(username)) {
req.setAttribute("msg", "用户名已存在!");
req.getRequestDispatcher("/register.jsp").forward(req, resp);
}else if(!affirm.equals(password)) {
req.setAttribute("msg", "两次输入的密码不一致!");
req.getRequestDispatcher("/register.jsp").forward(req, resp);
}else {
udi.insertUsers(new Users(username, password, email));
req.getSession().setAttribute("regist", "yes");
resp.sendRedirect("/jsp_day2/private/registsuccess.jsp");
}
}
}
3.registsuccess.jsp
介绍: 注册成功后跳转的界面。负责展示注册成功的信息并自动跳转到登录界面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>注册成功界面</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="refresh" content="3;URL=/jsp_day2/login.jsp">
</head>
<body>
<div id="regSuccess" class="png"></div>
<div style="margin:100px auto auto auto; width:400px; text-align:center"><font size="5px">注册成功!即将跳转至登录界面~~</font></div>
<br>
</body>
</html>
五、展示层
1.showMsg.jsp
介绍: 登陆成功后跳转的界面。负责展示所有收件人是登陆者的信息,默认是未读状态,信封闭合。当用户查看后,变为已读状态,信封打开。
<%@ page language="java" import="java.util.*,dao.*,entity.*"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>学士后 在线短信平台</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<div id="main">
<div class="mainbox">
<div class="title myMessage png"></div>
<div class="menu">
<span>当前用户:<a href="/jsp_day2/private/main.jsp"><%=session.getAttribute("name")%></a></span>
<span><a href="/jsp_day2/private/newMsg.jsp">发短消息</a></span> <span><a
href="/jsp_day2/closesession">退出</a></span>
</div>
<div class="content messageList">
<ul>
<%
UsersDaoImpl udi = new UsersDaoImpl();
Integer uid = (Integer) session.getAttribute("uid");
List<Message> msgList = udi.selectAllWithThis(uid);
for (Message msg : msgList) {
Integer msgid = msg.getMessageId();
if (msg.getFlag() == 0) {
%>
<li class="unReaded">
<%
} else {
%>
<li>
<%
}
%><em><%=msg.getSendDate()%></em> <em><a href="/jsp_day2/private/replyMsg.jsp?msgid=<%=msgid %>&sendname=<%=msg.getSenderName() %>&state=1">回信</a></em>
<em><a href=/jsp_day2/check/delete?msgid=<%=msgid %>>删除</a></em>
<p>
<strong><a href="/jsp_day2/private/readMsg.jsp?msgid=<%=msgid %>&state=1"><%=msg.getTitle()%></a></strong>
<%=msg.getContents()%>
<%
}
%>
</p>
</ul>
</div>
</div>
</div>
</body>
</html>
2.readMsg.jsp
介绍: 将用户点击的信息详情展示出来,供用户阅读查看
<%@page import="dao.UsersDaoImpl"%>
<%@ page language="java" import="java.util.*,entity.*"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>学士后 在线短信平台</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%
String state = request.getParameter("state");
String msgId = request.getParameter("msgid");
UsersDaoImpl udi = new UsersDaoImpl();
if (state != null && msgId != null) {
Integer intState = Integer.parseInt(state);
Integer mid = Integer.parseInt(msgId);
udi.updateFlag(intState, mid);
}
%>
</head>
<body>
<div id="main">
<div class="mainbox">
<%
String msgid = request.getParameter("msgid");
Integer mid = Integer.parseInt(msgid);
Message msg = udi.selectMessageByMsgId(mid);
%>
<div class="title readMessage png"></div>
<div class="menu">
<span>当前用户:<a href="/jsp_day2/private/main.jsp"><%=session.getAttribute("name")%></a></span>
<span><a href="/jsp_day2/private/newMsg.jsp">发短消息</a></span><span><a
href="/jsp_day2/private/showMsg.jsp">返回首页</a></span> <span><a href="/closesession">退出</a></span>
</div>
<div class="content">
<div class="message">
<div class="tmenu">
<ul class="clearfix">
<li>题目:<%=msg.getTitle()%>
</li>
<li>来自:<%=msg.getSenderName()%></li>
<li>时间:<%=msg.getSendDate()%></li>
</ul>
</div>
<div class="view">
<p><%=msg.getContents()%></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
六、操作层
1.查看资料或修改
①main.jsp
介绍: 当用户点击用户名时跳转的界面。展示用户的个人资料,可供修改。接收MainAction传递的错误信息并出现弹窗提示
<%@ page language="java" import="java.util.*,dao.*,entity.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>学士后 在线短信平台</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%
UsersDaoImpl udi = new UsersDaoImpl();
String un = (String)session.getAttribute("name");
Users us = udi.queryUsersByUserName(un);
String msg = (String) request.getAttribute("msg");
if (msg != null && !msg.equals("")) {
%><script type="text/javascript">alert("<%=msg%>")
<%}%>
</script>
</head>
<body>
<div id="mainTitle" class="png"></div>
<div id="regForm" class="userForm png">
<form action="/jsp_day2/check/main" method="post">
<dl>
<dt>用 户 名:</dt>
<dd>
<input type="text" name="username"
value="<%=un%>" readonly="readonly" />
</dd>
<dt>密 码:</dt>
<dd>
<input type="text" value="<%=us.getPassword()%>" name="password" />
</dd>
<dt>邮 箱:</dt>
<dd>
<input type="text" value="<%=us.getEmail() %>" name="email" />
</dd>
</dl>
<div class="buttons">
<input class="main-update png" type="submit" name="update" value=" " />
<input class="main-reset png" type="reset" name="reset" value=" " />
</div>
<div class="goback">
<a href="/jsp_day2/private/showMsg.jsp" class="png">返回首页</a>
</div>
</form>
</div>
</body>
</html>
②MainAction
介绍: 当用户点击修改按钮时跳转的界面。用于判断用户修改的资料合法性,如果不合法,将错误信息放入request作用域并转发到main.jsp界面,如果合法,跳转至mainsuccess.jsp
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dao.UsersDaoImpl;
import entity.Users;
public class MainAction extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 3796831561391949937L;
private static final UsersDaoImpl udi = new UsersDaoImpl();
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String password = req.getParameter("password");
String email = req.getParameter("email");
HttpSession session = req.getSession();
session.setAttribute("mainsuccess", "no");
if (!email.contains("@") || !email.contains(".") || email.lastIndexOf("@") > email.indexOf(".")
|| email.lastIndexOf("@") > email.lastIndexOf(".")) {
req.setAttribute("msg", "邮箱不合法!");
req.getRequestDispatcher("/private/main.jsp").forward(req, resp);
} else {
udi.updateUsers(new Users((String)session.getAttribute("name"),password,email));
req.getSession().setAttribute("mainsuccess", "yes");
resp.sendRedirect("/jsp_day2/private/mainsuccess.jsp");
}
}
}
③mainsuccess.jsp
介绍: 当修改成功后,跳转的界面。负责展示修改成功的信息并自动跳转至首页(showMsg.jsp)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>修改成功界面</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<meta http-equiv="refresh" content="3;URL=/jsp_day2/private/showMsg.jsp">
</head>
<body>
<div id="regSuccess" class="png"></div>
<div style="margin:100px auto auto auto; width:400px; text-align:center"><font size="5px">修改成功!即将跳转至首页~~</font></div>
<br>
</body>
</html>
2.发送或回复消息
①replyMsg.jsp
介绍: 当用户点击回复超链接后跳转的界面,并接受超链接传递过来的msgid。默认接收方为该信息发送者
<%@ page language="java" import="java.util.*,dao.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>学士后 在线短信平台</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%
String msg = (String) request.getAttribute("msg");
if (msg != null && !msg.equals("")) {
%><script type="text/javascript">alert("<%=msg%>")
</script>
<%
}
String state = request.getParameter("state");
String msgId = request.getParameter("msgid");
UsersDaoImpl udi = new UsersDaoImpl();
if (state != null && msgId != null) {
Integer intState = Integer.parseInt(state);
Integer mid = Integer.parseInt(msgId);
udi.updateFlag(intState, mid);
}
%>
</head>
<body>
<form action="/jsp_day2/check/send" method="post">
<div id="main">
<div class="mainbox">
<div class="menu">
<span>当前用户:<a href="/jsp_day2/private/main.jsp"><%=(String) session.getAttribute("name")%></a></span>
<span><a href="/jsp_day2/private/newMsg.jsp">发短消息</a></span><span><a
href="/jsp_day2/private/showMsg.jsp">返回首页</a></span> <span><a
href="/jsp_day2/closesession">退出</a></span>
</div>
<div class="content">
<div class="message">
<form method="post">
<div class="tmenu">
<ul class="clearfix">
<li>发送给: <select name="recname">
<%
List<String> unList = udi.selectAll((String) session.getAttribute("name"));
String sendname = request.getParameter("sendname");
for (String name : unList) {
if (name.equals(sendname)) {
%>
<option selected="selected" value="<%=name%>"><%=name%></option>
<%
} else {
%>
<option value="<%=name%>"><%=name%></option>
<%
}
%>
<%
}
%>
</select>
</li> 标题:
<input type="text" name="title" />
</ul>
</div>
<div class="view">
<textarea name="contents"></textarea>
<div class="send">
<input type="submit" name="submit" value=" " />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
②newMsg.jsp
介绍: 和replyMsg差不多,只是默认接收方不同
<%@ page language="java" import="java.util.*,dao.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>学士后 在线短信平台</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<%
String msg = (String) request.getAttribute("msg");
if (msg != null && !msg.equals("")) {
%><script type="text/javascript">alert("<%=msg%>")
</script>
<%
}
String state = request.getParameter("state");
String msgId = request.getParameter("msgid");
UsersDaoImpl udi = new UsersDaoImpl();
if (state != null && msgId != null) {
Integer intState = Integer.parseInt(state);
Integer mid = Integer.parseInt(msgId);
udi.updateFlag(intState, mid);
}
%>
</head>
<body>
<form action="/jsp_day2/check/send" method="post">
<div id="main">
<div class="mainbox">
<div class="menu">
<span>当前用户:<a href="main.jsp"><%=(String) session.getAttribute("name")%></a></span>
<span><a href="/jsp_day2/private/newMsg.jsp">发短消息</a></span><span><a
href="/jsp_day2/private/showMsg.jsp">返回首页</a></span> <span><a
href="/jsp_day2/closesession">退出</a></span>
</div>
<div class="content">
<div class="message">
<form method="post">
<div class="tmenu">
<ul class="clearfix">
<li>发送给: <select name="recname">
<%
List<String> unList = udi.selectAll((String) session.getAttribute("name"));
boolean bn = true;
for (String name : unList) {
if (bn) {
bn = false;
%>
<option selected="selected" value="<%=name%>"><%=name%></option>
<%
} else {
%>
<option value="<%=name%>"><%=name%></option>
<%
}
%>
<%
}
%>
</select>
</li> 标题:
<input type="text" name="title" />
</ul>
</div>
<div class="view">
<textarea name="contents"></textarea>
<div class="send">
<input type="submit" name="submit" value=" " />
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
③SendMsgAction
介绍: 负责接收replyMsg.jsp或newMsg.jsp传递过来的数据。判断是否合法,如果不合法,将结果放入request作用域并转发回去。如果合法,跳转至sendsuccess.jsp界面
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.UsersDaoImpl;
import entity.Message;
import entity.Users;
public class SendMsgAction extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -5920117313720382072L;
private static final UsersDaoImpl udi = new UsersDaoImpl();
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String title = req.getParameter("title");
String contents = req.getParameter("contents");
Integer sendid = (Integer) req.getSession().getAttribute("uid");
String recname = req.getParameter("recname");
String msg;
if (title.equals("")) {
msg = "标题不能为空!";
req.setAttribute("msg", msg);
req.getRequestDispatcher("/private/newMsg.jsp").forward(req, resp);
} else if (contents.equals("")) {
msg = "内容不能为空!";
req.setAttribute("msg", msg);
req.getRequestDispatcher("/private/newMsg.jsp").forward(req, resp);
}else {
Users us = udi.queryUsersByUserName(recname);
udi.insertMessage(new Message(title, contents, sendid, us.getUsersId()));
resp.sendRedirect("/jsp_day2/private/sendsuccess.jsp");
}
}
}
④sendsuccess.jsp
介绍: 当发送成功后跳转的界面。负责向用户展示发送成功的提示,当用户点击继续发送,则跳转至newMsg.jsp界面,当用户点击返回首页,跳转到showMsg.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>发送状态</title>
<link type="text/css" rel="stylesheet" href="css/sms.css" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
<div id="sendSuccess" class="png"
style="display:flex;
flex-direction: row;
justify-content: space-around;
align-items: center;">
<font size="5px" style="color:#F9F900">发送成功!</font>
</div>
<div
style="margin:100px auto auto auto; width:400px; text-align:center">
<div class="goback">
<a href="/jsp_day2/private/newMsg.jsp"><font size="5px" style="color:#FF0080">继续发送</font></a>
<a href="/jsp_day2/private/showMsg.jsp" class="png"><font size="5px" style="color:#0000C6">返回首页</font></a>
</div>
</div>
</body>
</html>
3. 删除信息
介绍: 当用户点击删除的超链接后,接收删除的msgid并调用dao层方法将其从数据库表中删除
package servlet;
import java.io.IOException;
import java.util.LinkedHashSet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dao.UsersDaoImpl;
public class DeleteMsgAction extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -1566135640888064603L;
private static final UsersDaoImpl udi = new UsersDaoImpl();
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String[] msgid = req.getParameterValues("msgid");
if (msgid.length > 0) {
LinkedHashSet<Integer> msgIdSet = new LinkedHashSet<>();
for (String msgId : msgid) {
msgIdSet.add(Integer.parseInt(msgId));
}
udi.deleteAll(msgIdSet);
}
resp.sendRedirect("/jsp_day2/private/showMsg.jsp");
}
}
4.CloseSessionAction
介绍: 当用户点击退出超链接跳转的界面。主要是删除session信息,实现安全退出的功能
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CloseSessionAction extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -4639818064873612493L;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getSession().invalidate();
resp.sendRedirect("/jsp_day2/login.jsp");
}
}
七、过滤层
1.CaracterEncodingFilter
介绍: 指定编码格式的过滤器
package filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class CharacterEncodingFilter implements Filter {
private String encoding;
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
request.setCharacterEncoding(encoding);
response.setCharacterEncoding(encoding);
chain.doFilter(request, response);
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
encoding = filterConfig.getInitParameter("encoding");
}
}
2.CheckNomalCommingFilter
介绍: 检查是否为正常请求,并通过不同的非法请求将其重定向到对应的界面
package filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class CheckNomalCommingFilter implements Filter {
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpSession session = req.getSession();
HttpServletResponse resp = (HttpServletResponse) response;
String un = (String) session.getAttribute("name");
session.getAttribute("regist");
String path = req.getServletPath();
String unRegist = req.getParameter("username");
String recName = req.getParameter("recname");
String unLogin = unRegist;
String replyId = req.getParameter("msgid");
String mainEmail = req.getParameter("email");
String mainSuccess = (String) session.getAttribute("mainsuccess");
// 先判断是不是注册请求,如果是就进行筛选
if (path.contains("/regist")) {
if ((path.equals("/check/regist") && unRegist == null) || (path.contains("/registsuccess.jsp")
&& (session.getAttribute("regist") == null || session.getAttribute("regist").equals("no")))) {
resp.sendRedirect("/jsp_day2/register.jsp");
} else {
chain.doFilter(request, response);
}
// 如果不是注册请求,进行第二轮筛选
} else if (un == null && unLogin == null) {
resp.sendRedirect("/jsp_day2/login.jsp");
} else if (path.contains("/check/send") && recName == null) {
resp.sendRedirect("/jsp_day2/private/newMsg.jsp");
} else if (path.contains("replyMsg") && (replyId==null || replyId.equals(""))) {
resp.sendRedirect("/jsp_day2/private/showMsg.jsp");
} else if ((path.contains("/check/main") && mainEmail == null)
|| (path.contains("/mainsuccess") && mainSuccess == null)) {
resp.sendRedirect("/jsp_day2/private/showMsg.jsp");
} else {
chain.doFilter(request, response);
}
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
}
八、dao层
1.UsersDao接口
介绍: 声明了一下需要用到的方法
package dao;
import java.util.LinkedHashSet;
import java.util.List;
import entity.Message;
import entity.Users;
public interface UsersDao {
// // 通过用户名查询密码和id
// public String[] queryPasswordByUserName(String username);
// 根据用户名查询该用户的全部信息
public Users queryUsersByUserName(String username);
// 判断用户名是否存在
public boolean ifExistToUserName(String username);
// 修改用户信息
public void updateUsers(Users u);
// 往users表中添加一条用户信息
public boolean insertUsers(Users u);
// 往message表中添加一条信息
public boolean insertMessage(Message m);
// 根据收件人编号,返回所有跟该用户有关的信息
public List<Message> selectAllWithThis(Integer receiverId);
// 返回除自身外的所有用户姓名
public List<String> selectAll(String username);
// 通过id查询用户姓名
public String selectOne(Integer usersid);
// 获取下一个用户表的序列值
public int getUsersSeq();
// 获取下一个信息表的序列值
public int getMessageSeq();
// 通过id批量删除短信
public void deleteAll(LinkedHashSet<Integer> messageIdSet);
// 修改阅读标记
public void updateFlag(Integer flag,Integer msgid);
// 根据msgid查看具体内容
public Message selectMessageByMsgId(Integer msgid);
// 获取当前时间
public String getTime();
}
2.UsersDaoImpl实现类
介绍: 实现了UsersDao接口中的方法,供业务层调用
package dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import org.junit.Test;
import entity.Message;
import entity.Users;
import utils.JdbcUtils;
public class UsersDaoImpl implements UsersDao {
/**
* 根据用户名查询用户全部信息
*/
@Override
public Users queryUsersByUserName(String username) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("select USERSID,PASSWORD,EMAIL from users where username = ?");
ps.setString(1, username);
rs = ps.executeQuery();
if (rs.next()) {
return new Users(rs.getInt(1), username, rs.getString(2), rs.getString(3));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return null;
}
@Test
public void testQueryUsersByUserName() {
Users us = queryUsersByUserName("zxw");
System.out.println(us.getUsersId());
}
/**
* 判断用户名是否存在 存在-true 不存在-false
*/
@Override
public boolean ifExistToUserName(String username) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("select password from users where username = ?");
ps.setString(1, username);
rs = ps.executeQuery();
return rs.next();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return false;
}
/**
* 往users表中添加一条用户信息 添加成功-true 添加失败-false
*/
@Override
public boolean insertUsers(Users p) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("insert into users values(users_seq.nextVal,?,?,?)");
ps.setString(1, p.getUsername());
ps.setString(2, p.getPassword());
ps.setString(3, p.getEmail());
ps.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return false;
}
@Test
public void testInsertUsers() {
insertUsers(new Users("zxw", "123456", "aaa@qq.com"));
}
/**
* 往users表中添加一条用户信息 添加成功-true 添加失败-false
*/
@Override
public boolean insertMessage(Message m) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("insert into message values(users_seq.nextVal,?,?,?,?,?,0)");
ps.setString(1, m.getTitle());
ps.setString(2, m.getContents());
ps.setInt(3, m.getSenderId());
ps.setInt(4, m.getReceiverId());
ps.setString(5, getTime());
ps.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return false;
}
/**
* 修改阅读标记flag
*/
@Override
public void updateFlag(Integer flag, Integer msgid) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("update message set flag=? where messageid = ?");
ps.setInt(1, flag);
ps.setInt(2, msgid);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
}
/**
* 修改用户的资料 参数为:修改后的资料信息
*/
@Override
public void updateUsers(Users u) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("update users set PASSWORD=?,EMAIL=? where USERNAME = ?");
ps.setString(1, u.getPassword());
ps.setString(2, u.getEmail());
ps.setString(3, u.getUsername());
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
}
/**
* 根据msgid查看具体内容 返回一个Message对象(title,contents,senderid,senddate)
*/
@Override
public Message selectMessageByMsgId(Integer msgid) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
Message msg = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("SELECT TITLE,CONTENTS,SENDERID,SENDDATE FROM MESSAGE WHERE MESSAGEID = ?");
ps.setInt(1, msgid);
rs = ps.executeQuery();
if (rs.next()) {
msg = new Message(rs.getString(1), rs.getString(2), rs.getInt(3), rs.getString(4));
msg.setSenderName(selectOne(msg.getSenderId()));
}
return msg;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return null;
}
@Test
public void testSelectMessageByMsgId() {
Message msg = selectMessageByMsgId(2);
// System.out.println(msg);
System.out.println(msg.getTitle() + "-" + msg.getContents() + "-" + msg.getSendDate());
}
private static boolean closeConn = true;
/**
* 根据收件人编号,查询所有跟该用户有关的短信
*/
@Override
public List<Message> selectAllWithThis(Integer receiverId) {
List<Message> list = new ArrayList<Message>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement(
"SELECT MESSAGEID,SENDERID,TITLE,CONTENTS,SENDDATE,FLAG FROM MESSAGE WHERE RECEIVERID = ?");
ps.setInt(1, receiverId);
rs = ps.executeQuery();
while (rs.next()) {
closeConn = false;
Integer msgid = rs.getInt(1);
Integer senderid = rs.getInt(2);
String title = rs.getString(3);
String contents = rs.getString(4);
String sendDate = rs.getString(5);
Integer flag = rs.getInt(6);
Message msg = new Message(msgid, senderid, title, contents, sendDate, flag);
msg.setReceiverName(selectOne(receiverId));
msg.setSenderName(selectOne(senderid));
list.add(msg);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
} finally {
closeConn = true;
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return null;
}
@Test
public void testSelectAllWithThis() {
List<Message> msgList = selectAllWithThis(3);
for (Message msg : msgList) {
System.out.println(msg.getReceiverName() + "-" + msg.getContents() + "\t" + msg.getSendDate());
}
}
/**
* 返回除自身外的所有用户的姓名
*/
@Override
public List<String> selectAll(String username) {
List<String> list = new ArrayList<String>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("select USERNAME from USERS order by USERNAME DESC");
rs = ps.executeQuery();
while (rs.next()) {
String name = rs.getString(1);
if (!name.equals(username))
list.add(name);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return null;
}
@Test
public void testSelectAll() {
List<String> names = selectAll("zxw");
for (String name : names) {
System.out.println(name);
}
}
/**
* 根据id查询用户姓名
*/
@Override
public String selectOne(Integer id) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("SELECT USERNAME FROM USERS WHERE USERSID = ?");
ps.setInt(1, id);
rs = ps.executeQuery();
if (rs.next())
return rs.getString(1);
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return null;
}
/**
* 获取下一个用户表的序列值
*/
@Override
public int getUsersSeq() {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("select users_seq.nextVal from dual");
rs = ps.executeQuery();
if (rs.next())
return rs.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return 0;
}
/**
* 获取下一个信息表的序列值
*/
@Override
public int getMessageSeq() {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JdbcUtils.getConnection();
ps = conn.prepareStatement("select message_seq.nextVal from dual");
rs = ps.executeQuery();
if (rs.next())
return rs.getInt(1);
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, rs);
}
return 0;
}
/**
* 根据用户选中短信的id,进行批量删除
*/
@Override
public void deleteAll(LinkedHashSet<Integer> messageIdSet) {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = JdbcUtils.getConnection();
for (Integer id : messageIdSet) {
ps = conn.prepareStatement("delete MESSAGE where MESSAGEID = ?");
ps.setInt(1, id);
ps.executeUpdate();
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JdbcUtils.closeAll(closeConn ? conn : null, ps, null);
}
}
/**
* 获取当前时间并返回
*/
@Override
public String getTime() {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
@Test
public void testGetTime() {
System.out.println(getTime());
}
}
九、其它类和xml配置文件
1.JdbcUtils工具类
介绍: 利用druid连接池技术,获取Connection对象和关闭资源的方法
package utils;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
public class JdbcUtils {
// 封装一个数据库连接池对象
private static DataSource ds;
// 加载驱动
static {
try {
Properties pro = new Properties();
// 创建一个输入流对象读取数据
InputStream path = JdbcUtils.class.getResourceAsStream("/druid.properties");
pro.load(path);
ds = DruidDataSourceFactory.createDataSource(pro);
} catch (Exception e1) {
e1.printStackTrace();
}
}
// 创建一个ThreadLocal对象
private static final ThreadLocal<Connection> local1 = new ThreadLocal<>();
// 根据帐号密码获取Connetion对象
public static Connection getConnection(String userName, String password) {
try {
if (local1.get() == null) {
local1.set(ds.getConnection());
}
return local1.get();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
// 创建一个ThreadLocal对象
private static final ThreadLocal<Connection> local2 = new ThreadLocal<>();
// 获取默认帐号密码的Connection对象
public static Connection getConnection() {
try {
if (local2.get() == null) {
local2.set(ds.getConnection());
}
return local2.get();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
// 关闭所有资源
public static void closeAll(Connection conn, PreparedStatement ps, ResultSet rs) {
if (conn != null) {
try {
if (local1.get() != null) {
local1.remove();
} else if (local2.get() != null) {
local2.remove();
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
// 关闭Connection
public static void closeOne(Connection conn) {
if (conn != null) {
try {
if (local1.get() != null) {
local1.remove();
} else if (local2.get() != null) {
local2.remove();
}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
2.Users类
介绍: 实体类,将数据库中users表的一些字段封装成了一个类
package entity;
import java.io.Serializable;
public class Users implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5066504410672831873L;
private Integer usersId;
private String username;
private String password;
private String email;
public Users() {
}
public Users(Integer usersId,String username, String password, String email) {
super();
this.usersId = usersId;
this.username = username;
this.password = password;
this.email = email;
}
public Users(String username, String password, String email) {
super();
this.username = username;
this.password = password;
this.email = email;
}
public Integer getUsersId() {
return usersId;
}
public void setUsersId(Integer usersId) {
this.usersId = usersId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
3.Message类
介绍: 将数据库中message表的字段封装成了一个类
package entity;
import java.io.Serializable;
public class Message implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5030350304739834635L;
private Integer messageId;
private String title;
private String contents;
private String senderName;
private String receiverName;
private Integer senderId;
private Integer receiverId;
private String sendDate;
private Integer flag;
public Message() {
}
public Message(Integer messageId,String title, String contents, String senderName, String receiverName, Integer senderId,
Integer receiverId,String sendDate, Integer flag) {
super();
this.messageId = messageId;
this.title = title;
this.contents = contents;
this.senderName = senderName;
this.receiverName = receiverName;
this.senderId = senderId;
this.receiverId = receiverId;
this.sendDate = sendDate;
this.flag = flag;
}
public Message(String title, String contents, Integer senderId,Integer receiverId) {
super();
this.title = title;
this.contents = contents;
this.senderId = senderId;
this.receiverId = receiverId;
}
public Message(Integer messageId,Integer senderId,String title, String contents, String sendDate,Integer flag) {
super();
this.messageId = messageId;
this.senderId = senderId;
this.title = title;
this.contents = contents;
this.sendDate = sendDate;
this.flag = flag;
}
public Message(String title, String contents, String senderName, String sendDate) {
super();
this.title = title;
this.contents = contents;
this.senderName = senderName;
this.sendDate = sendDate;
}
public Message(String title, String contents, Integer senderId, String sendDate) {
super();
this.title = title;
this.contents = contents;
this.senderId = senderId;
this.sendDate = sendDate;
}
public String getSendDate() {
return sendDate;
}
public void setSendDate(String sendDate) {
this.sendDate = sendDate;
}
public Integer getMessageId() {
return messageId;
}
public void setMessageId(Integer messageId) {
this.messageId = messageId;
}
public String getSenderName() {
return senderName;
}
public void setSenderName(String senderName) {
this.senderName = senderName;
}
public String getReceiverName() {
return receiverName;
}
public void setReceiverName(String receiverName) {
this.receiverName = receiverName;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContents() {
return contents;
}
public void setContents(String contents) {
this.contents = contents;
}
public Integer getSenderId() {
return senderId;
}
public void setSenderId(Integer senderId) {
this.senderId = senderId;
}
public Integer getReceiverId() {
return receiverId;
}
public void setReceiverId(Integer receiverId) {
this.receiverId = receiverId;
}
public Integer getFlag() {
return flag;
}
public void setFlag(Integer flag) {
this.flag = flag;
}
}
4.web.xml
介绍: 存放配置信息
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<!-- 字符编码集过滤器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 检查是否正常访问的过滤器 -->
<filter>
<filter-name>CheckNomalCommingFilter</filter-name>
<filter-class>filter.CheckNomalCommingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CheckNomalCommingFilter</filter-name>
<url-pattern>/check/*</url-pattern>
<url-pattern>/private/*</url-pattern>
</filter-mapping>
<!-- 判断登陆的Action -->
<servlet>
<servlet-name>LoginAction</servlet-name>
<servlet-class>servlet.LoginAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginAction</servlet-name>
<url-pattern>/check/login</url-pattern>
</servlet-mapping>
<!-- 判断注册的Action -->
<servlet>
<servlet-name>RegistAction</servlet-name>
<servlet-class>servlet.RegistAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistAction</servlet-name>
<url-pattern>/check/regist</url-pattern>
</servlet-mapping>
<!-- 批量删除短信的Action -->
<servlet>
<servlet-name>DeleteAction</servlet-name>
<servlet-class>servlet.DeleteMsgAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DeleteAction</servlet-name>
<url-pattern>/check/delete</url-pattern>
</servlet-mapping>
<!-- 清理session的Action -->
<servlet>
<servlet-name>CloseSessionAction</servlet-name>
<servlet-class>servlet.CloseSessionAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CloseSessionAction</servlet-name>
<url-pattern>/closesession</url-pattern>
</servlet-mapping>
<!-- 发送消息的Action -->
<servlet>
<servlet-name>SendMsgAction</servlet-name>
<servlet-class>servlet.SendMsgAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SendMsgAction</servlet-name>
<url-pattern>/check/send</url-pattern>
</servlet-mapping>
<!-- 查看和修改资料的Action -->
<servlet>
<servlet-name>MainAction</servlet-name>
<servlet-class>servlet.MainAction</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MainAction</servlet-name>
<url-pattern>/check/main</url-pattern>
</servlet-mapping>
</web-app>
十、页面效果图
对于这里我说一下啊, 不知道为啥我导入进去的图片它不显示,然后就看不到那个确定和重置按钮了。。。 我还特地去阿里图库去下载的,汗!~~