Advertisement
Guest User

bobo

a guest
Feb 24th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package servlet;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5. import java.lang.reflect.Type;
  6. import java.util.List;
  7.  
  8. import javax.servlet.ServletConfig;
  9. import javax.servlet.ServletException;
  10. import javax.servlet.http.HttpServlet;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13.  
  14. import com.google.gson.Gson;
  15. import com.google.gson.reflect.TypeToken;
  16.  
  17. import bean.BeanArticle;
  18. import bean.BeanAuthentification;
  19. import bean.BeanEquipement;
  20. import entite.Article;
  21.  
  22. /**
  23.  * Servlet implementation class Control
  24.  */
  25. public class Control extends HttpServlet {
  26.     private static final long serialVersionUID = 1L;
  27.    
  28.     /**
  29.      * @see HttpServlet#HttpServlet()
  30.      */
  31.     public Control() {
  32.         super();
  33.     }
  34.  
  35.     /**
  36.      * @see Servlet#init(ServletConfig)
  37.      */
  38.     public void init(ServletConfig config) throws ServletException {
  39.         // TODO Auto-generated method stub
  40.     }
  41.  
  42.     /**
  43.      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
  44.      *      response)
  45.      */
  46.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  47.             throws ServletException, IOException {
  48.         response.setContentType("application/json;charset=UTF-8");     
  49.        
  50.         try (PrintWriter out = response.getWriter()){
  51.            
  52.         BeanArticle a = new BeanArticle();                 
  53.         Gson gson = new Gson();
  54.         Type type = new TypeToken<List<Article>>() {}.getType();
  55.         String json = gson.toJson(a.findArticle(), type);      
  56.         out.write(json);
  57.        
  58.        
  59.         }
  60.  
  61.     }
  62.  
  63.     /**
  64.      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
  65.      *      response)
  66.      */
  67.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  68.             throws ServletException, IOException {
  69.  
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement