⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 artshow.java

📁 前台:文章浏览、发表留言、Game、Music 后台:文章相关:发表文章、修改文章、删除文章、批量移动文章 栏目相关:增加栏目、修改栏目、删除栏目、栏目链接、栏目排序系统栏目分为系统内部栏目和外部栏目
💻 JAVA
字号:
package com.yhcms.article.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.yhcms.utils.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.yhcms.article.bean.Article;
import com.yhcms.article.dao.ArticleDaoIm;
import com.yhcms.article.itface.ArticleDao;
import com.yhcms.db.DBConnException;
import com.yhcms.utils.ReqUtils;

/**
 * <p>Title:系统显示文章Action</p>
 * <li>显示文章</li>
 * <li>从Request取得文章Id,然后取得文章对象显示</li>
 * <br><b>CopyRight: yyhweb[由由华网]</b>
 * @author stephen
 * @version YH-2.0
 */
public class ArtShow extends Action {
	public ActionForward execute(ActionMapping actionmapping,ActionForm form,
			 HttpServletRequest request,HttpServletResponse response){
		
		Logger yhlog = Logger.getLogger(ArtShow.class.getName());
				
		String content = "";
		int bid = 0;
		int artId = ReqUtils.getInt(request,"artId");
		int p = ReqUtils.getInt(request,"p");
		String linkInfo = "";
		int cLength = 0;  // 文章内容的长度
		int pgCount = 0; //  文章页数
		int pSize = 3000;
		int tmpl = 0;
		int tmps = 0;
		List pnlist = new ArrayList(); // 该文章相关文章列表
		ArticleDao artdao = ArticleDaoIm.getInstance();
		Article curArt = null; // 此时的Article对象 只需要一个Dto 就可以了,故此处用到ArtShowDto
		try {
			curArt = (Article)artdao.getArticleById(artId);
			
			if(curArt!=null){
				bid = curArt.getBid();
				pnlist = artdao.getPreNextArt(artId,bid);
				if(p==0){
					artdao.addOneReadTime(artId);
				}
				content = curArt.getContent();
				curArt.setContent("");
				cLength = content.length();
				tmpl = cLength/pSize;
				
				if(cLength > pSize){
					if(p<=0){
						p = 1;
					}
					tmps = p*pSize;
					pgCount = (cLength%pSize)!=0?(tmpl+1):tmpl;
					linkInfo = subPageLink(pgCount,artId,p,"ArtShow.html?artId="+artId);
					content = content.substring((p-1)*pSize,tmps>cLength?cLength:tmps);
				}
			}else{
				curArt = new Article();
				//  取得文章出错或者artId<=0的话,记录一个错误.
				yhlog.info("Get an article unsuccessfully.");
				request.setAttribute("article",curArt);
				return actionmapping.findForward("Show");
			}
		}catch (DBConnException e) {
			yhlog.warn("When get an article to show,throw an Exception!The article id is:"+artId+".");
		}
		
		content = StringUtils.ubbEncode((content));
		request.setAttribute("article",curArt);
		request.setAttribute("cInfo",linkInfo);
		request.setAttribute("content",content);
		request.setAttribute("pnlist",pnlist);
		return actionmapping.findForward("Show");

		}
	
	/**
	 * @param c 文章分页数目
	 * @param artId 文章Id
	 * @param p 当前页码
	 * @param link 链接字符串
	 * @return 链接字符串
	 */
	public String subPageLink(int c,int artId,int p,String link){
		String str = "";
		StringBuffer sb = new StringBuffer();
		sb.append("文章共 "+c+" 页&nbsp;&nbsp;[&nbsp;&nbsp;&nbsp;");
		for(int i=0;i<c;i++){
			if((i+1)==p){
				sb.append("<b>");
				sb.append((i+1));
				sb.append("</b>");
				sb.append("&nbsp;&nbsp;");
				continue;
			}
			sb.append("<a href=");
			sb.append(link+"&p="+(i+1)+">");
			sb.append((i+1));
			sb.append("</a>");
			sb.append("&nbsp;&nbsp;");
		}
		sb.append("&nbsp;]");
		str = sb.toString();
		sb = null;
		return str;
		
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -