// 生成home页面的主文章列表html代码 public String generateHomeMainHtml(List<TArticle> articles) throws Exception { String listHtml = ""; if (articles != null) { int size = articles.size(); for (int i = 0; i < size; i++) { TArticle article = articles.get(i); // 组织标签的html String tagsHtml = ""; String[] tags = article.getArticle_Tag().split(","); for (int j = 0; j < tags.length; j++) { String tag = URLEncoder.encode(URLEncoder.encode(tags[j], "utf-8")); if (j == 0) { tagsHtml += "<a title='" + tags[j] + "' rel='tag' href='/doit/search/" + tag + "/0/2/search' style='font-size:13px;'>" + tags[j] + "</a>"; } else { tagsHtml += " , <a title='" + tags[j] + "' rel='tag' href='/doit/search/" + tag + "/0/2/search' style='font-size:13px;'>" + tags[j] + "</a>"; } } OperateString operateString = new OperateString(); String contentHtml = article.getArticle_Content(); // String contentHtml = "dsafkjbsdkds<pre class='brush: js;'>function // helloSyntaxHighlighter(){return 'hi!';}</pre><div class='ui segment '><img src='123.png' // /><IMG src='456.png' /></div>afkjbsdkdsafkjbsdk中文结尾"; // 过滤图片 OperateImage operateImage = new OperateImage(); contentHtml = operateImage.filterImage(contentHtml); // 过滤html所有标签 contentHtml = operateString.filterHtmlTag(contentHtml); // 截取字符串 contentHtml = operateString.interceptCharacters(contentHtml, 0, 200); String item = ""; item += "<div id='item" + article.getArticle_ID() + "' class='ui stacked segment'>"; item += " <h2 class='article_title'>"; item += " <a href='/doit/show/" + article.getArticle_ID() + "' style='font-size:24px;'>" + article.getArticle_Title() + "</a>"; item += " </h2>"; item += " <h2></h2>"; item += " <div class='article_date'>"; item += " <span property='dc:date dc:created' content='2013-11-10T12:30:01+08:00' datatype='xsd:dateTime' rel='sioc:has_creator' style='margin-right:20px;'> 发布时间 : " + article.getArticle_Date() + " </span>"; item += " <span style='color:#434A54;'>Tags : </span>"; item += tagsHtml; item += " </div>"; item += " <div class='row'>"; item += " <a class='thumbnail' href='/doit/show/" + article.getArticle_ID() + "' style='float:left;width:240px;oveflow:hidden;'>"; item += " <img src='" + article.getArticle_Cover() + "' style='height: 175px; width: 100%; display: block;' data-src='holder.js/100%x175'>"; item += " </a>"; item += " <span id='artContent" + article.getArticle_ID() + "' class='sDiv article_content'>" + contentHtml + "</span>"; item += " </div>"; item += "</div>"; listHtml += item; } } System.out.println(listHtml); return listHtml; }