Correction exercice 04 serie 01 servlet

Correction exercice 04 serie 01 servlet

  1. Exercice 04

    1. Énoncé
    2. Solution



      • 
        
        import java.io.IOException;
        import java.io.PrintWriter;
        
        import javax.servlet.ServletException;
        import javax.servlet.annotation.WebServlet;
        import javax.servlet.http.HttpServlet;
        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;
        
        /**
         * Servlet implementation class ServletTableMultiplication
         */
        @WebServlet("/ServletTableMultiplication")
        public class ServletTableMultiplication extends HttpServlet {
        	private static final long serialVersionUID = 1L;
               
            /**
             * @see HttpServlet#HttpServlet()
             */
            public ServletTableMultiplication() {
                super();
                // TODO Auto-generated constructor stub
            }
        
        	/**
        	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
        	 */
        	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
        			throws ServletException, IOException {
        		// TODO Auto-generated method stub
        		response.getWriter().append("Served at: ").append(request.getContextPath());
        		response.setContentType("text/html") ;	
        		PrintWriter out = response.getWriter() ;
        		out.println("<html>") ;
        		out.println("<head>") ;
        		out.println("<title>CréationTableauMu</title>") ;
        		out.println("</head>") ;
        		out.println("<body>") ;
        		///////////////////////////////
        		out.println("<center>");
        		 
        		/** Mettre un titre pour la table*/
        		out.println("<caption> Table de multiplication</caption>");
        		 
        		/* Créer la table*/
        		out.println("<table width='60%' border=1>");
        		 
        		 
        		/* Créer la première ligne */
        		out.println("<tr><td bgcolor='#FFff00'  align='center'><strong>"+"x"+"</strong></td>");
        		 
        		for(int i=1;i<=10;i++)
        		{
        			out.println("<td bgcolor='#D1D7D6' align='center'><strong>"+i+"</strong></td>");
        		}
        		out.println("</tr>");
        		/* créer les autres lignes*/
        		for(int i=1;i<11;i++)
        		{
        			/* Créer la ligne numéro i*/
        			out.println("<tr>");
        			out.println("<td bgcolor='#D1D7D6'  align='center'><strong>"+i+"</strong></td>");
        		     	for(int j=1;j<=10;j++)
        		      	{
        		          /* Créer la colonne numéro j*/
        		     		out.println("<td align='center'>"+i*j+"</td>");
        			}
        		     	out.println("</tr>");
        		}
        		out.println("</table>");
        		
        		////////////////////
        		
        		
        		
        		out.println("</body>") ;
        		out.println("</html>") ;
        	}
        
        	/**
        	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
        	 */
        	protected void doPost(HttpServletRequest request, 
        HttpServletResponse response) throws ServletException, IOException {
        		// TODO Auto-generated method stub
        		doGet(request, response);
        	}
        
        }
        



Abonnez vous à notre chaîne YouTube gratuitement