SHARE
TWEET

Untitled

a guest Nov 14th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package ca.qc.cgodin.controllers;
  2.  
  3. import java.io.IOException;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.annotation.WebServlet;
  6. import javax.servlet.http.HttpServlet;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9.  
  10. /**
  11.  * Servlet implementation class firstServlet
  12.  */
  13. @WebServlet("/firstServlet")
  14. public class firstServlet extends HttpServlet {
  15.     private static final long serialVersionUID = 1L;
  16.        
  17.     /**
  18.      * @see HttpServlet#HttpServlet()
  19.      */
  20.     public firstServlet() {
  21.         super();
  22.         // TODO Auto-generated constructor stub
  23.     }
  24.  
  25.     @Override
  26.     protected void doDelete(HttpServletRequest request, HttpServletResponse response)
  27.             throws ServletException, IOException {
  28.         // TODO Auto-generated method stub
  29.        
  30.         response.getWriter().append("Votre requet HTTP DELETE est recue");
  31.         response.getWriter().append("\n");
  32.         response.getWriter().append("En cours de traitement");
  33.     }
  34.  
  35.     @Override
  36.     protected void doPut(HttpServletRequest request, HttpServletResponse response)
  37.             throws ServletException, IOException {
  38.         // TODO Auto-generated method stub
  39.        
  40.         response.getWriter().append("Votre requet HTTP PUT est recue");
  41.         response.getWriter().append("\n");
  42.         response.getWriter().append("En cours de traitement");
  43.     }
  44.  
  45.     /**
  46.      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  47.      */
  48.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  49.        
  50.         //recouperer le numero envoye par l'utilisateur utilisand request
  51.        
  52.         int number=Integer.parseInt(request.getParameter("number"));
  53.        
  54.         //teste si number est par ou impair
  55.        
  56.         if(number%2==0){
  57.             response.getWriter().write(number + " " + "est pair");
  58.             response.getWriter().append("\n");
  59.         }else{
  60.             response.getWriter().write(number + " " + "est impair");
  61.             response.getWriter().append("\n");
  62.         }
  63.         response.getWriter().append("\n");
  64.         response.getWriter().append("Votre requet HTTP GET est recue");
  65.         response.getWriter().append("\n");
  66.         response.getWriter().append("En cours de traitement");
  67.         //response.setStatus(204);// no impact no response to request
  68.     }
  69.  
  70.     /**
  71.      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  72.      */
  73.     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  74.         // TODO Auto-generated method stub
  75.         response.getWriter().append("Votre requet HTTP POST est recue");
  76.         response.getWriter().append("\n");
  77.         response.getWriter().append("En cours de traitement");
  78.     }
  79.    
  80.    
  81.  
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top