1. 展示博客具体内容
2.设计到点击量 所以多加一个点击量字段
3.评论内容
3.1 记录用户IP地址
4.jsp展示页面
1 <%@ page language="java" contentType="text/html; charset=gb2312" 2 pageEncoding="gb2312"%> 3 <%@taglib uri="/struts-tags" prefix="s"%> 4 <%@ taglib uri="http://java.fckeditor.net" prefix="FCK"%> 5 6 7 8我的文章 9 10 11 12 13 14 15 1617130 13118124 129c 1933${empty sessionScope.blogtitle ? "博客网站系统":sessionScope.blogtitle} 20 ${empty sessionScope.idiograph ? "我的签名":sessionScope.idiograph} 21
222325 32» Font Size «2434 9899100122101 110111 121123
5.
1 package com.sanqing.action; 2 3 import java.text.SimpleDateFormat; 4 import java.util.Date; 5 import java.util.Map; 6 7 import javax.servlet.http.HttpServletRequest; 8 9 import org.apache.struts2.ServletActionContext; 10 11 import com.opensymphony.xwork2.ActionContext; 12 import com.opensymphony.xwork2.ActionSupport; 13 import com.sanqing.fenye.Page; 14 import com.sanqing.fenye.Result; 15 import com.sanqing.po.Article; 16 import com.sanqing.po.BlogInfo; 17 import com.sanqing.service.ArticleService; 18 import com.sanqing.service.BlogInfoService; 19 import com.sanqing.service.CritiqueService; 20 import com.sanqing.service.DianjiliangService; 21 22 public class ShowArticle extends ActionSupport { 23 // 业务逻辑组件属性 24 private ArticleService articleService; 25 // id属性 26 private int id; 27 // 点击量的业务逻辑组件 28 private DianjiliangService dianjiliangService; 29 // 评论的业务逻辑组件 30 private CritiqueService critiqueService; 31 //设置当前页 32 private int currentPage; 33 34 //username 35 private String username; 36 37 private BlogInfoService blogInfoService; 38 39 public BlogInfoService getBlogInfoService() { 40 return blogInfoService; 41 } 42 43 public void setBlogInfoService(BlogInfoService blogInfoService) { 44 this.blogInfoService = blogInfoService; 45 } 46 47 public String getUsername() { 48 return username; 49 } 50 51 public void setUsername(String username) { 52 this.username = username; 53 } 54 55 public int getCurrentPage() { 56 return currentPage; 57 } 58 59 public void setCurrentPage(int currentPage) { 60 this.currentPage = currentPage; 61 } 62 63 public CritiqueService getCritiqueService() { 64 return critiqueService; 65 } 66 67 public void setCritiqueService(CritiqueService critiqueService) { 68 this.critiqueService = critiqueService; 69 } 70 71 public DianjiliangService getDianjiliangService() { 72 return dianjiliangService; 73 } 74 75 public void setDianjiliangService(DianjiliangService dianjiliangService) { 76 this.dianjiliangService = dianjiliangService; 77 } 78 79 public int getId() { 80 return id; 81 } 82 83 public void setId(int id) { 84 this.id = id; 85 } 86 87 public ArticleService getArticleService() { 88 return articleService; 89 } 90 91 public void setArticleService(ArticleService articleService) { 92 this.articleService = articleService; 93 } 94 95 public String execute() throws Exception { 96 // 将文章设置到request范围 97 HttpServletRequest request = ServletActionContext.getRequest(); 98 // 按ID查询文章 99 Article article = articleService.showArticle(id);100 // 获得用户IP101 String IP = request.getRemoteAddr();102 // 获得当前时间103 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");104 String stime = sdf.format(new Date());105 Date time = sdf.parse(stime);106 107 if (!dianjiliangService.isVistor(id, IP, time)) {108 // 点击量增加109 article.setHasread(article.getHasread() + 1);110 }111 // 将更新的Article保存到数据表中112 articleService.addArticle(article);113 114 115 //显示评论116 Page page = new Page();117 page.setCurrentPage(this.getCurrentPage());118 page.setEveryPage(5);119 120 Result result = critiqueService.showCritiqueByPage(id, page);121 122 request.setAttribute("page", result.getPage());123 request.setAttribute("allCri", result.getList());124 request.setAttribute("article", article);125 126 //取得个性化设置127 //通过业务逻辑组件来查询128 if(username != null || !"".equals(username)) {129 Map session = ActionContext.getContext().getSession();130 BlogInfo bloginfo = blogInfoService.getBlogInfo(username);131 if(bloginfo != null) {132 session.put("blogtitle", bloginfo.getBlogtitle());133 session.put("idiograph", bloginfo.getIdiograph());134 }135 }136 return this.SUCCESS;137 }138 139 }
6 strut2.xml
<action name="addCritique" class="addCritique">
<result name="success" type="chain">showArticle</result> </action>