东华理工大学长江学院毕业设计 第6章 系统详细设计与实现
(4) 相册管理模块
相册管理模块博主可以上传照片、查看照片、删除照片,其中上传照片使用了Struts2的 // 设置两个变量分别接受上传过来的文件的属性 private File picture; //上传的文件 private String pictureFileName; //文件名称 // 由于上传到服务器上的图片文件为临时文件,所以要将临时文件保存到服务器上的指定文件夹中,以便读取。 private void upLoad() { String parent = ServletActionContext. getServletContext().getRealPath(\ String path = parent + \ photo.setPhotoAddr(path); // 将上传的路径存储在数据库中 File saved = new File(parent, pictureFileName); InputStream ins = null; OutputStream ous = null; try {saved.getParentFile().mkdirs(); ins = new FileInputStream(picture); ous = new FileOutputStream(saved); byte[] b = new byte[1024]; int len = 0; while ((len = ins.read(b)) != -1) { ous.write(b, 0, len); } } catch (Exception e) { e.printStackTrace(); } finally { if(ous != null) try { ous.close(); } catch (IOException e) { e.printStackTrace(); } if(ins != null) try { ins.close(); } catch (IOException e) { e.printStackTrace(); } } } 31 东华理工大学长江学院毕业设计 第6章 系统详细设计与实现 // 上传照片 public String uploadPhoto() { this.upLoad(); Date date = new Date(); // 上传时间 String str_date = new String(new SimpleDateFormat (\ photo.setPhotoTime(str_date); photo.setPhotoName(pictureFileName); int user = (Integer)ActionContext.getContext() .getSession().get(\ photo.setUserId(user); if(photoService.uploadPhoto(photo)) { return SUCCESS; } else { return \ } } 如图6-7为上传相片的界面显示: 图6-7为上传相片 (5) 好友管理模块 好友管理模块同样实现了对好友的增、删、改、查功能,实现方法和文章模块类似,在此不多做说明。 如图6-8为好友列表的界面显示: 32 东华理工大学长江学院毕业设计 第6章 系统详细设计与实现 图6-8为好友列表 六.留言管理模块 留言管理模块实现了对好友的删、查功能,实现方法和文章模块类似,在此不多做说明。 如图6-9为留言列表的界面显示: 图6-9 留言列表 6.3.2 前台:用户界面模块 该模块是针对所有网民设计的,所有的注册和非注册用户均可以浏览博主的博 33 东华理工大学长江学院毕业设计 第6章 系统详细设计与实现 客,拥有查看博文、查看相册、留言、评论、查看好友等权限。 (1) 博文欣赏 在数据库中取出对应用户的文章,并在前台显示。 1. 如图6-10为浏览博文界面显示: 图6-10 博文欣赏 2. 图6-11为查看博文界面显示: 图6-11 查看博文界面 34 东华理工大学长江学院毕业设计 第6章 系统详细设计与实现 3. 图6-12为给博文添加评论界面显示: 图6-12 评论日志 (2) 相册 1. 如图6-13为浏览相册界面显示: 图6-13 浏览相册 35