BlogServlet.java.svn-base
上传用户:cdpainuo
上传日期:2022-07-12
资源大小:5257k
文件大小:2k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.appspot.cindyblog.servlet;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import javax.persistence.EntityManager;
  5. import javax.servlet.ServletException;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import com.appspot.cindyblog.common.EMF;
  10. import com.appspot.cindyblog.pojo.ArticleBean;
  11. import com.appspot.cindyblog.pojo.DiscussBean;
  12. import com.appspot.cindyblog.pojo.LinkBean;
  13. import com.appspot.cindyblog.pojo.MessageBean;
  14. import com.appspot.cindyblog.pojo.TypeBean;
  15. public class BlogServlet extends BaseServlet {
  16. private static final long serialVersionUID = 5709330878821727568L;
  17. public void doGet(HttpServletRequest request, HttpServletResponse response)
  18. throws ServletException, IOException {
  19. String m = request.getParameter("m");
  20. if("getIndex".equals(m)){
  21. this.getIndex(request, response);
  22. }
  23. }
  24. public void getIndex(HttpServletRequest request, HttpServletResponse response)
  25. throws ServletException, IOException {
  26. response.setContentType("text/html;charset=utf-8");
  27. EntityManager em = null;
  28. try{
  29. bs = getBlogService();
  30. em = EMF.get().createEntityManager();
  31. String rz = bs.getObjectList(ArticleBean.class, em, "time", 0, 5);
  32. String ly = bs.getObjectList(MessageBean.class, em, "time", 0, 5);
  33. String fl = bs.getObjectList(TypeBean.class, em);
  34. String pl = bs.getObjectList(DiscussBean.class, em, "time", 0, 5);
  35. String link = bs.getObjectList(LinkBean.class, em);
  36. String str = "var elements = {nodes:{ly:"+ly+",fl:"+fl+",rz:"+rz+",pl:"+pl+",link:"+link+"}}";
  37. response.getWriter().print(str);
  38. }catch(Exception e){
  39. e.printStackTrace();
  40. }finally{
  41. closeEntityManager(em);
  42. }
  43. }
  44. }