返回顶部

完整项目总结(项目:中国收藏品集市)

 

一.项目介绍

.该项目是由我(宋zy♂)和另外三个同学(刘yc♂,付jy♀,周p♂)一起做的,主要实现了中国收藏品集市(http://1688nn.com/)的4个模块以及一些琐碎的小功能,如下所示为该项目大致结构图:

1.mvc设计模式图

mvc设计模式图

2.模块

用户模块

用户模块JSP文件路径:CurioNet/WebRoot/page/user

 CurioNet/src/com/curionet/dao/user接口

CurioNet/src/com/curionet/dao/user/impl接口实现

CurioNet/src/com/curionet/user/service业务接口

CurioNet/src/com/curionet/user/service/impl接口实现

CurioNet/src/com/curionet/user/web/Servlet 页面跳转(服务逻辑处理)

 

论坛模块

 

论坛模块JSP文件路径:CurioNet/WebRoot/page/forum

CurioNet/src/com/curionet/dao/forum接口

forumInter.java(用到自定义的抽象方法)增 删   查(可根据多项查询)

CurioNet/src/com/curionet/dao/forum/impl接口实现

forumImpl.java抽象方法的实现()

CurioNet/src/com/curionet/forum/service业务接口

CurioNet/src/com/curionet/forum/service/impl接口实现

CurioNet/src/com/curionet/forum/web/Servlet 页面跳转(服务逻辑处理)

 

拍卖模块

 

拍卖模块JSP文件路径:CurioNet/WebRoot/page/auction

CurioNet/src/com/curionet/dao/auction接口

auctionInter.java(用到自定义的抽象方法)增 删 改 查(可根据多项查询)

CurioNet/src/com/curionet/dao/auction/impl接口实现

auctionImpl.java抽象方法的实现()

CurioNet/src/com/curionet/auction/service业务接口

CurioNet/src/com/curionet/auction/service/impl接口实现

CurioNet/src/com/curionet/auction/web/Servlet 页面跳转(服务逻辑处理) 

 

 

新闻模块

JSP文件路径:CurioNet/WebRoot/page/journalism

CurioNet/src/com/curionet/dao/journalism接口

journalismInter.java(用到自定义的抽象方法)增 删   查(可根据多项查询)

CurioNet/src/com/curionet/dao/journalism/impl接口实现

journalismImpl.java抽象方法的实现()

CurioNet/src/com/curionet/journalism/service业务接口

CurioNet/src/com/curionet/journalism/service/impl接口实现

CurioNet/src/com/curionet/journalism/web/Servlet 页面跳转(服务逻辑处理)

 

 二.项目运行截图(选取的几张)

注册

首页

登录

论坛1

论坛2

新闻1

新闻2

三.数据库设计

论坛:
1.user:用户基本信息表
字段:
user_id
user_name
email
homepage
tel
address
2.forum_item论坛表(主题表)
字段:
f_id
user_id
f_title
f_content:帖子的内容
f_publishtime:发布时间
f_count:统计浏览次数
3.forum_item_back:主题回复表
字段:
id
f_topic_id:几楼
user_id
f_title
f_content
f_replytime


拍卖:
1.拍卖表Product_sal
字段:
user_name:商品所有者
p_id:商品编号
p_price:商品价格
p_sal:销售数量
P_promise:承诺
p_viewcount:浏览次数
P_state:销售状态
p_date:上传时间


2.商品表Product
p_id:商品编号
p_num:商品数量
p_condition:品相
P_time:商品年代
p_particular:商品详情

新闻资讯:

2.news(新闻表)
字段:
n_id:
user_id:发布者
n_title
n_content:帖子的内容
n_publishtime:发布时间
n_count:统计浏览次数

 四.代码展示(选取一部分,想要完整代码联系我qq:1136747328)

选取的是注册登录的servlet,参考了itcast的部分代码

  1 package com.dingli.curionet.user.web.servlet;
  2 
  3     import java.io.IOException;
  4     import java.net.URLEncoder;
  5     import java.util.HashMap;
  6     import java.util.Map;
  7 
  8     import javax.servlet.ServletException;
  9     import javax.servlet.http.Cookie;
 10     import javax.servlet.http.HttpServletRequest;
 11     import javax.servlet.http.HttpServletResponse;
 12     import javax.servlet.http.HttpSession;
 13 
 14     import cn.itcast.commons.CommonUtils;
 15     import  com.dingli.curionet.user.entity.User;
 16 import com.dingli.curionet.user.service.UserService;
 17 
 18     import com.dingli.curionet.user.service.exception.UserException;
 19 import cn.itcast.servlet.BaseServlet;
 20 
 21     /**
 22      * 用户模块WEB层
 23      * @author qdmmy6
 24      *
 25      */
 26     public class UserServlet extends BaseServlet {
 27         private UserService userService = new UserService();
 28         
 29         /**
 30          * ajax用户名是否注册校验
 31          * @param req
 32          * @param resp
 33          * @return
 34          * @throws ServletException
 35          * @throws IOException
 36          */
 37         public String ajaxValidateLoginname(HttpServletRequest req, HttpServletResponse resp)
 38                 throws ServletException, IOException {
 39             /*
 40              * 1. 获取用户名
 41              */
 42             String loginname = req.getParameter("loginname");
 43         
 44             /*
 45              * 2. 通过service得到校验结果
 46              */
 47             boolean b = userService.ajaxValidateLoginname(loginname);
 48             /*
 49              * 3. 发给客户端
 50              */
 51             resp.getWriter().print(b);
 52             return null;
 53         }
 54         
 55         /**
 56          * ajax Email是否注册校验
 57          * @param req
 58          * @param resp
 59          * @return
 60          * @throws ServletException
 61          * @throws IOException
 62          */
 63         public String ajaxValidateEmail(HttpServletRequest req, HttpServletResponse resp)
 64                 throws ServletException, IOException {
 65             /*
 66              * 1. 获取Email
 67              */
 68             String email = req.getParameter("email");
 69             /*
 70              * 2. 通过service得到校验结果
 71              */
 72             boolean b = userService.ajaxValidateEmail(email);
 73             /*
 74              * 3. 发给客户端
 75              */
 76             resp.getWriter().print(b);
 77             return null;
 78         }
 79         
 80         /**
 81          * ajax验证码是否正确校验
 82          * @param req
 83          * @param resp
 84          * @return
 85          * @throws ServletException
 86          * @throws IOException
 87          */
 88         public String ajaxValidateVerifyCode(HttpServletRequest req, HttpServletResponse resp)
 89                 throws ServletException, IOException {
 90             /*
 91              * 1. 获取输入框中的验证码
 92              */
 93             String verifyCode = req.getParameter("verifyCode");
 94             /*
 95              * 2. 获取图片上真实的校验码
 96              */
 97             String vcode = (String) req.getSession().getAttribute("vCode");
 98             /*
 99              * 3. 进行忽略大小写比较,得到结果
100              */
101             boolean b = verifyCode.equalsIgnoreCase(vcode);
102             /*
103              * 4. 发送给客户端
104              */
105             resp.getWriter().print(b);
106             return null;
107         }
108 
109         /**
110          * 注册功能
111          * @param req
112          * @param resp
113          * @return
114          * @throws ServletException
115          * @throws IOException
116          */
117         public String regist(HttpServletRequest req, HttpServletResponse resp)
118                 throws ServletException, IOException {
119             /*
120              * 1. 封装表单数据到User对象
121              */
122             User formUser = CommonUtils.toBean(req.getParameterMap(), User.class);
123             /*
124              * 2. 校验之, 如果校验失败,保存错误信息,返回到regist.jsp显示
125              */
126             Map<String,String> errors = validateRegist(formUser, req.getSession());
127             if(errors.size() > 0) {
128                 req.setAttribute("form", formUser);
129                 req.setAttribute("errors", errors);
130                 return "f:/jsps/user/regist.jsp";
131             }
132             /*
133              * 3. 使用service完成业务
134              */
135             userService.regist(formUser);
136             /*
137              * 4. 保存成功信息,转发到msg.jsp显示!
138              */
139             req.setAttribute("code", "success");
140             req.setAttribute("msg", "注册功能,请马上到邮箱激活!");
141             return "f:/jsps/msg.jsp";
142         }
143         
144         /*
145          * 注册校验
146          * 对表单的字段进行逐个校验,如果有错误,使用当前字段名称为key,错误信息为value,保存到map中
147          * 返回map
148          */
149         private Map<String,String> validateRegist(User formUser, HttpSession session) {
150             Map<String,String> errors = new HashMap<String,String>();
151             /*
152              * 1. 校验登录名
153              */
154             String loginname = formUser.getLoginname();
155             if(loginname == null || loginname.trim().isEmpty()) {
156                 errors.put("loginname", "用户名不能为空!");
157             } else if(loginname.length() < 3 || loginname.length() > 20) {
158                 errors.put("loginname", "用户名长度必须在3~20之间!");
159             } else if(!userService.ajaxValidateLoginname(loginname)) {
160                 errors.put("loginname", "用户名已被注册!");
161             }
162             
163             /*
164              * 2. 校验登录密码
165              */
166             String loginpass = formUser.getLoginpass();
167             if(loginpass == null || loginpass.trim().isEmpty()) {
168                 errors.put("loginpass", "密码不能为空!");
169             } else if(loginpass.length() < 3 || loginpass.length() > 20) {
170                 errors.put("loginpass", "密码长度必须在3~20之间!");
171             }
172             
173             /*
174              * 3. 确认密码校验
175              */
176             String reloginpass = formUser.getReloginpass();
177             if(reloginpass == null || reloginpass.trim().isEmpty()) {
178                 errors.put("reloginpass", "确认密码不能为空!");
179             } else if(!reloginpass.equals(loginpass)) {
180                 errors.put("reloginpass", "两次输入不一致!");
181             }
182             
183             /*
184              * 4. 校验email
185              */
186             String email = formUser.getEmail();
187             if(email == null || email.trim().isEmpty()) {
188                 errors.put("email", "Email is null!");
189             } else if(!email.matches("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$")) {
190                 errors.put("email", "Email is wrong!");
191             } else if(!userService.ajaxValidateEmail(email)) {
192                 errors.put("email", "Email已被注册!");
193             }
194             
195             /*
196              * 5. 验证码校验
197              */
198             String verifyCode = formUser.getVerifyCode();
199             String vcode = (String) session.getAttribute("vCode");
200             if(verifyCode == null || verifyCode.trim().isEmpty()) {
201                 errors.put("verifyCode", "验证码不能为空!");
202             } else if(!verifyCode.equalsIgnoreCase(vcode)) {
203                 errors.put("verifyCode", "验证码错误!");
204             }
205             
206             return errors;
207         }
208         
209         /**
210          * 激活功能
211          * @param req
212          * @param resp
213          * @return
214          * @throws ServletException
215          * @throws IOException
216          */
217         public String activation(HttpServletRequest req, HttpServletResponse resp)
218                 throws ServletException, IOException {
219             /*
220              * 1. 获取参数激活码
221              * 2. 用激活码调用service方法完成激活
222              *   > service方法有可能抛出异常, 把异常信息拿来,保存到request中,转发到msg.jsp显示
223              * 3. 保存成功信息到request,转发到msg.jsp显示。
224              */
225             String code = req.getParameter("activationCode");
226             try {
227                 userService.activatioin(code);
228                 req.setAttribute("code", "success");//通知msg.jsp显示对号
229                 req.setAttribute("msg", "恭喜,激活成功,请马上登录!");
230             } catch (UserException e) {
231                 // 说明service抛出了异常
232                 req.setAttribute("msg", e.getMessage());
233                 req.setAttribute("code", "error");//通知msg.jsp显示X
234             }
235             return "f:/jsps/msg.jsp";
236         }
237         
238         /**
239          * 修改密码 
240          * @param req
241          * @param resp
242          * @return
243          * @throws ServletException
244          * @throws IOException
245          */
246         public String updatePassword(HttpServletRequest req, HttpServletResponse resp)
247                 throws ServletException, IOException {
248             /*
249              * 1. 封装表单数据到user中
250              * 2. 从session中获取uid
251              * 3. 使用uid和表单中的oldPass和newPass来调用service方法
252              *   > 如果出现异常,保存异常信息到request中,转发到pwd.jsp
253              * 4. 保存成功信息到rquest中
254              * 5. 转发到msg.jsp
255              */
256             User formUser = CommonUtils.toBean(req.getParameterMap(), User.class);
257             User user = (User)req.getSession().getAttribute("sessionUser");
258             // 如果用户没有登录,返回到登录页面,显示错误信息
259             if(user == null) {
260                 req.setAttribute("msg", "您还没有登录!");
261                 return "f:/jsps/user/login.jsp";
262             }
263             
264             try {
265                 userService.updatePassword(user.getUid(), formUser.getNewpass(), 
266                         formUser.getLoginpass());
267                 req.setAttribute("msg", "修改密码成功");
268                 req.setAttribute("code", "success");
269                 return "f:/jsps/msg.jsp";
270             } catch (UserException e) {
271                 req.setAttribute("msg", e.getMessage());//保存异常信息到request
272                 req.setAttribute("user", formUser);//为了回显
273                 return "f:/jsps/user/pwd.jsp";
274             }
275         }
276         
277         /**
278          * 退出功能
279          * @param req
280          * @param resp
281          * @return
282          * @throws ServletException
283          * @throws IOException
284          */
285         public String quit(HttpServletRequest req, HttpServletResponse resp)
286                 throws ServletException, IOException {
287             req.getSession().invalidate();
288             return "r:/jsps/user/login.jsp";
289         }
290         
291         /**
292          * 登录功能
293          * @param req
294          * @param resp
295          * @return
296          * @throws ServletException
297          * @throws IOException
298          */
299         public String login(HttpServletRequest req, HttpServletResponse resp)
300                 throws ServletException, IOException {
301             /*
302              * 1. 封装表单数据到User
303              * 2. 校验表单数据
304              * 3. 使用service查询,得到User
305              * 4. 查看用户是否存在,如果不存在:
306              *   * 保存错误信息:用户名或密码错误
307              *   * 保存用户数据:为了回显
308              *   * 转发到login.jsp
309              * 5. 如果存在,查看状态,如果状态为false:
310              *   * 保存错误信息:您没有激活
311              *   * 保存表单数据:为了回显
312              *   * 转发到login.jsp
313              * 6. 登录成功:
314              *   * 保存当前查询出的user到session中
315              *   * 保存当前用户的名称到cookie中,注意中文需要编码处理。
316              */
317             /*
318              * 1. 封装表单数据到user
319              */
320             User formUser = CommonUtils.toBean(req.getParameterMap(), User.class);
321             /*
322              * 2. 校验
323              */
324             Map<String,String> errors = validateLogin(formUser, req.getSession());
325             if(errors.size() > 0) {
326                 req.setAttribute("form", formUser);
327                 req.setAttribute("errors", errors);
328                 return "f:/jsps/user/login.jsp";
329             }
330             
331             /*
332              * 3. 调用userService#login()方法
333              */
334             User user = userService.login(formUser);
335             /*
336              * 4. 开始判断
337              */
338             if(user == null) {
339                 req.setAttribute("msg", "用户名或密码错误!");
340                 req.setAttribute("user", formUser);
341                 return "f:/jsps/user/login.jsp";
342             } else {
343                 if(!user.isStatus()) {
344                     req.setAttribute("msg", "您还没有激活!");
345                     req.setAttribute("user", formUser);
346                     return "f:/jsps/user/login.jsp";                
347                 } else {
348                     // 保存用户到session
349                     req.getSession().setAttribute("sessionUser", user);
350                     // 获取用户名保存到cookie中
351                     String loginname = user.getLoginname();
352                     loginname = URLEncoder.encode(loginname, "utf-8");
353                     
354                     Cookie cookie = new Cookie("loginname", loginname);
355                     cookie.setMaxAge(60);
356                     cookie.setMaxAge(60 * 60 * 24 * 10);//保存10天
357                     resp.addCookie(cookie);
358                     return "r:/index.jsp";//重定向到主页
359                 }
360             }
361         }
362         
363     
364         private Map<String,String> validateLogin(User formUser, HttpSession session) {
365             Map<String,String> errors = new HashMap<String,String>();
366             return errors;
367         }
368     }

五.项目总结

第一次团队做项目,有点乱,每个人都自己做自己的,导致整合的时候出现各中bug,但是这算是一次完整的项目,以后可以改正。另外博客写的有些匆忙,不好的地方多多谅解,我会努力改正。

 

posted @ 2017-08-16 11:16  或许舞恋步  阅读(1197)  评论(2)    收藏  举报