Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package servlet;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.lang.reflect.Type;
- import java.util.List;
- import javax.servlet.ServletConfig;
- import javax.servlet.ServletException;
- import javax.servlet.annotation.WebServlet;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.google.gson.Gson;
- import com.google.gson.reflect.TypeToken;
- import bean.BeanArticle;
- import bean.BeanAuthentification;
- import bean.BeanEquipement;
- import entite.Article;
- /**
- * Servlet implementation class Control
- */
- //@WebServlet("/control")
- public class Control extends HttpServlet {
- private static final long serialVersionUID = 1L;
- protected void processRequest(HttpServletRequest req, HttpServletResponse rep)
- throws ServletException, IOException {
- rep.setContentType("application/json");
- req.getRequestDispatcher("/WEB-INF/index.html").forward(req, rep);
- BeanArticle a = new BeanArticle();
- Gson gson = new Gson();
- Type type = new TypeToken<List<Article>>() {}.getType();
- String json = gson.toJson(a.findArticle(), type);
- PrintWriter out = rep.getWriter();
- out.print(json);
- out.flush();
- }
- /**
- * @see HttpServlet#HttpServlet()
- */
- public Control() {
- super();
- }
- /**
- * @see Servlet#init(ServletConfig)
- */
- public void init(ServletConfig config) throws ServletException {
- // TODO Auto-generated method stub
- }
- /**
- * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
- * response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- /**
- * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
- * response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment