www.pudn.com > Jsp-Blog.rar > IndexServlet.java, change:2010-05-26,size:1739b


package myblog.servlet; 
 
import java.io.IOException; 
import java.util.ArrayList; 
 
import javax.servlet.ServletException; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import myblog.commons.ClickNumber; 
import myblog.dao.InformationCountDao; 
import myblog.dao.ShowLogDao; 
import myblog.entity.Logs; 
 
public class IndexServlet extends HttpServlet { 
 
	protected void doPost(HttpServletRequest request, 
			HttpServletResponse response) { 
		Object username = request.getSession().getAttribute("username"); 
		/** 
		 * 如果未登录,则为游客身份 
		 */ 
		 
		if(username==null){ 
			username="tourist"; 
			request.getSession().setAttribute("username", username); 
		} 
		/** 
		 * 显示日志 
		 */ 
		ArrayList<Logs> list = new ArrayList<Logs>(); 
		ShowLogDao show = new ShowLogDao(); 
		list = show.showLog(); 
		request.getSession().setAttribute("loglist", list); 
		/** 
		 * 显示统计信息 
		 */ 
		InformationCountDao infor=new InformationCountDao(); 
		//日志数目 
		int num1=infor.logCount(); 
		request.getSession().setAttribute("lognumber", num1); 
		//评论数目 
		int num2=infor.reviewCount(); 
		request.getSession().setAttribute("reviewnumber", num2); 
		//注册人数统计 
		int num3=infor.usersCount(); 
		request.getSession().setAttribute("usernumber", num3); 
		//点击量统计 
		int num4=ClickNumber.add(); 
		request.getSession().setAttribute("clicknumber", num4); 
		try { 
			request.getRequestDispatcher("index.jsp") 
					.forward(request, response); 
		} catch (ServletException e) { 
 
			e.printStackTrace(); 
		} catch (IOException e) { 
 
			e.printStackTrace(); 
		} 
	} 
}