WELCOME Abdennour : Software engineer

Sep 14, 2012

Servlet [tuto 3 J2EE]



     أ) Understand the benefits of programming with servlets

    ب) 
Life Cycle of Servlet : :

    ج)[TP] Developing a Simple Servlet:


     د) [TP]Retrieving data from a form (Récupération des données d'un formulaire) By Netbeans:


   و) [TP]Forms - Servlets and Methods Service / doGet / doPost (  Formulaires – Servlets et Méthode Service/doGet/doPost) : 

        >>Difference between the methods services / doGet / doPost and actions GET / POST:
    ز) [TP] The function controller (=Servlet ): Redirect page :





     أ) Understand the benefits of programming with servlets
-A Servlet is a Java Class which extends javax.servlet.http.HttpServlet . 
-The servlet runs on the Application  server and (generally) produces a HTML page which is displayed in your browser.

-The servlet represents the controller in MVC model .

  Example : 
       <>a Servlet which display data from From Html(Formulaire) ..
       <>a Servlet which insert data into DataBase .
       <>a Servlet which query the DataBase ...

-Servlet  replace CGI (Common Gateway Interface, a standard for dynamic generation of web pages by a web server)
-Servlet : 
   i) is more efficient than CGI:
     -Servlet is multi-threaded .
    -Servlet Manage Cache.

   ii)Servlet is more practical than CG
     -Java EE provides Super-Api to manage HTML forms, cookies, session tracking.
    -ease of handling of HTTP Protocol: Handle Http Header...
   iii)more powerful than CGI:
    -share data between servlets.
    -Session Management.
    -Chaining servlets (DB Connection pool).

But, What's the Difference between Servlet & Applet ? 


Applet runs on the client, servlet runs on the server. It's as simple as that.
More specifically, that applet is downloaded to the client, and executes in a JRE inside the browser, and can display whatever it wants to display within the applet frame. The servlet instead runs on the server and (generally) produces a HTML page which is displayed in your browser.

What's the Standard URL to invoke servlet : 

http://<domain>:<port>/<projectName>/<ServletName>
 Example : 
   - if we have Apache as Web Server & ServletSelem is a Servlet which says "السلام عليكم"
    -to invoke ServletSelem ,you should follow this steps : 
      i) Run Web Server & Application Server(Exp:Apache Tomcat)
      ii)Deploy your Project (which is named by example projectA)
      iii) enter this URL into your browser (it's an Example).
   http://localhost:8080/projectA/ServletSelem


fdf


    ب) Life Cycle of Servlet :

           i)Loading Servlets :
           
              -Servlets are loaded by the application server :
                   *A first Request(A la première demande)
                   OR
                   *At the start of AS(Au démarrage du SA)
                   OR
                   *On a request for recharging(Sur une demande de rechargement )
        ii)Main Methods Servlet : 

           - Init () is called once and only once when loading the Servlet
           -service () method is invoked for each client request
           -destroy () is called once and unloading of the Servlet



          iii)Servlets Management :




              iv)Basic Structure : 



    ج)[TP] Developing a Simple Servlet:        
   
-Video Tuto  :
                                                 

-Source Code  :
         
Add dynamic Code  inservlet



     د) [TP]Retrieving data from a form (Récupération des 

données d'un formulaire) By Netbeans:

>Project Architecture : 


 >Form in JSP File : 

>Servlet to retreive data


   
Explanation



RUN




                                                       











Source Code : 











   و) 
[TP]Forms - Servlets and Methods Service / doGet / doPost (  Formulaires – Servlets et Méthode Service/doGet/doPost) : 
>Video Tuto : 


  ز) [TP] The function controller (=Servlet ): Redirect page :

-In a MVC model, each component in the application must meet its role: Model, View and Control.
Since the servlet represents the controller in a JEE platform, clean code to get a  servlet  view code or model code.



so , let's do this schema : 

form.jsp 






-REFERENCE :
>Saloua ben Yahia Jee Courses .
>http://stackoverflow.com

No comments:

Post a Comment