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 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  6 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  7 <head>
  8 <title>我的文章</title>
  9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 10 <link type="text/css" rel="stylesheet" href="../css/main.css" media="all" />
 11 <!--[if IE 6]><link type="text/css" rel="stylesheet" href="css/ie6.css" media="all" /><![endif]-->
 12 <script type="text/javascript" src="../js/mootools.js"></script>
 13 <script type="text/javascript" src="../js/site.js"></script>
 14 </head>
 15 <body>
 16 <div id="wrapper">
 17   <div id="container">
 18     <div id="scene"> c<img src="../images/scene.jpg" alt="" />
 19        <h1>${empty sessionScope.blogtitle ? "博客网站系统":sessionScope.blogtitle} <br/>
 20               <font size="8">${empty sessionScope.idiograph ? "我的签名":sessionScope.idiograph}</font>
 21               </h1>
 22       <div id="scale_area">
 23         <div id="scale_knob">&raquo; Font Size &laquo;</div>
 24       </div>
 25       <div id="menu">
 26          <div class="holder"> <a href="../showAllArticle.action">博客首页</a> </div>
 27         <div class="holder"> <a href="showUserAllArticle.action">用户首页</a> </div>
 28         <div class="holder"> <a href="editbloginfo.jsp">个性化设置</a> </div>
 29         <div class="holder"> <a href="addArticle.jsp">写日志</a> </div>
 30         <div class="holder"> <a href="showPhoto.action">相册</a> </div>
 31       </div>
 32     </div>
 33     <div id="content">
 34       <div id="col_left">
 35         <div class="post">
 36           <div class="meta"><a class="title" href=""><s:property value="#request.article.title"/></a>
 37             <div class="clear"></div>
 38           </div>
 39           <div class="comments">
 40             <div class="comment">
 41               <div class="meta">
 42               <span><s:property value="#request.article.content" escape="false"/>
 43               </span>
 44                 <div class="clear"> </div>
 45               </div>
 46             </div>
 47             </div>
 48           </div>
 49         <!-- 循环输出 -->
 50         <s:set name="loushu" value="#request.page.beginIndex"></s:set>
 51         <s:iterator value="#request.allCri" id="cri">
 52         <s:set name="loushu" value="#loushu + 1"></s:set>
 53           <div class="comments">
 54             <div class="comment">
 55               <div class="meta"><span><s:property value="#cri.content" escape="false"/></span>
 56                 <div class="clear"><span class="datetime">作者:<s:property value="#cri.username"/></span></div>
 57               </div>
 58             </div>
 59           </div>
 60          </s:iterator>
 61           <div class="comment" align="center">
 62               当前第${page.currentPage}页,共${page.totalPage}页,每页显示${page.everyPage}条记录
 63             <s:if test="#request.page.hasPrePage">
 64                 <a href="showArticle.action?id=${requestScope.article.id}&currentPage=1">首页</a>
 65                 <a href="showArticle.action?id=${requestScope.article.id}&currentPage=${page.currentPage -1 }">上一页</a>
 66             </s:if>
 67             <s:else>
 68                 首页
 69                 上一页
 70             </s:else>
 71             
 72             <s:if test="#request.page.hasNextPage">
 73                 <a href="showArticle.action?id=${requestScope.article.id}&currentPage=${page.currentPage + 1 }">下一页</a>
 74                 <a href="showArticle.action?id=${requestScope.article.id}&currentPage=${page.totalPage }">尾页</a>            
 75             </s:if>
 76             <s:else>
 77                 下一页
 78                 尾页
 79             </s:else>
 80           </div>
 81           <div class="comment">
 82               <h2>发表评论</h2>
 83             <form class="h" action="addCritique.action" method="post">
 84             <input type="hidden" name="id" value='${requestScope.article.id }'/>
 85               <div>
 86                 <FCK:editor instanceName="content" basePath="/user/fckeditor" toolbarSet="myToolbar" height="400"></FCK:editor>
 87               </div>
 88               <div>
 89                 <label></label>
 90                 <div class="clear"> </div>
 91               </div>
 92               <div class="button_wrapper">
 93                 <input name="提交" type="submit" class="button" value="提交" />
 94               </div>
 95             </form>
 96           </div>
 97         </div>
 98       </div>
 99       <div id="col_right">
100         <div id="search_box">
101           <form action="" method="post">
102             <div>
103               <input type="text" name="search" />
104             </div>
105             <div class="button_wrapper">
106               <input type="submit" value="Search" class="button" />
107             </div>
108             <div class="clear"> </div>
109           </form>
110         </div>
111         <div id="sidebar">
112           <h2>页面导航</h2>
113           <ul>
114             <li><a href="../showAllArticle.action">博客首页</a></li>
115             <li><a href="showUserAllArticle.action">用户首页</a></li>
116             <li><a href="editbloginfo.jsp">个性化设置</a></li>
117             <li><a href="addArticle.jsp">写日志</a></li>
118                <li><a href="showPhoto.action">相册</a></li>
119           </ul>
120         </div>
121       </div>
122       <div class="clear"> </div>
123     </div>
124     <div id="footer">
125       <div class="clear"> </div>
126       <hr />
127       <p class="credit">博客网站系统</p>
128     </div>
129   </div>
130 </body>
131 </html>

 

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         // 获得用户IP
101         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>
       

posted on 2016-11-20 17:01  Sharpest  阅读(377)  评论(0编辑  收藏  举报