SlideShare uma empresa Scribd logo
1 de 10
Baixar para ler offline
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
Noël Macé
Formateur et Consultant indépendant expert Unix et FOSS
http://www.noelmace.com
Servlets
Java EE
Licence Creative Commons
Ce(tte) œuvre est mise à disposition selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 3.0 France.
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
Plan
• Qu'est qu'une servlet
• HttpServlet
• Requête
• Réponse
• Exemple
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
Qu'est qu'une servlet
• classe java dérivée de javax.servlet.http.HttpServlet
• permet la création dynamique de données
 au sain d'un serveur HTTP
 le plus souvent au format HTML
• exécution coté serveur
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
HttpServlet
• classe mère de toutes les servlets
• Méthodes
 void doGet(HttpServletRequest request, HttpServletResponse response)
• point d'entrée relatif à une requête HTTP GET
- <form ... method="GET">
- ou via l'url
 void doPost(HttpServletRequest request, HttpServletResponse response)
• point d'entrée relatif à une requête HTTP POST
- balise <form ... method="POST">
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
Requête
• interface javax.servlet.http.HttpServletRequest
• Méthode
 String getParameter(String arg0)
• permet de récupérer la valeur d'un paramêtre
•
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
Réponse
• interface javax.servlet.http.HttpServletResponse
• Méthodes
 setContentType
• spécifie le type MIME de la réponse
 java.io.OutputStream getOutputStream
• génère un OutputStream permettant l'envoi de données binaires
• ex : image JPEG
 java.io.PrintWriter getWriter
• génère un PrintWrier, permettant l'envoi du texte de réponse
• ex : HTML
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
Exemple
public class ServletHelloWorld extends HttpServlet
{
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
String texte = request.getParameter("test");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write("<html><head><title>Bienvenue</title></head>"
+ "<body><h1>Bienvenue</h1>" + "<p>Bonjour "
+ texte + "</p></body></html>");
}
}
public class ServletHelloWorld extends HttpServlet
{
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
String texte = request.getParameter("test");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write("<html><head><title>Bienvenue</title></head>"
+ "<body><h1>Bienvenue</h1>" + "<p>Bonjour "
+ texte + "</p></body></html>");
}
}
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
Configuration
• web/WEB-INF/web.xml
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Bienvenue</servlet-name>
<servlet-class>com.eteks.test.ServletBienvenue</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Bienvenue</servlet-name>
<url-pattern>/bienvenue</url-pattern>
</servlet-mapping>
</web-app>
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>Bienvenue</servlet-name>
<servlet-class>com.eteks.test.ServletBienvenue</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Bienvenue</servlet-name>
<url-pattern>/bienvenue</url-pattern>
</servlet-mapping>
</web-app>
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
Ce qu’on a couvert
• Génération dynamique de contenu web grâce aux servlets
 classes
 méthodes
 réponse et requète
FIN
Oracle Certified Professional, Java SE 7 Programmer noelmace.com
Licence
Ce(tte) œuvre (y compris ses illustrations, sauf mention explicite) est mise à disposition selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 3.0 France.
Pour voir une copie de cette licence, visitez http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ ou écrivez à :
Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
Vous êtes libre de :
 partager — reproduire, distribuer et communiquer cette œuvre
 remixer — adapter l’œuvre
Selon les conditions suivantes :
 Attribution — Vous devez clairement indiquer que ce document, ou tout document dérivé de celui, est (issu de) l’œuvre
originale de Noël Macé (noelmace.com) (sans suggérer qu'il vous approuve, vous ou votre utilisation de l’œuvre, à moins
d'en demander expressément la permission).
 Pas d’Utilisation Commerciale — Vous n’avez pas le droit d’utiliser cette œuvre à des fins commerciales (ie. l'intention
première ou l'objectif d'obtenir un avantage commercial ou une compensation financière privée). Pour obtenir ce droit, une
autorisation explicite de l'auteur est requise.
 Partage dans les Mêmes Conditions — Si vous modifiez, transformez ou adaptez cette œuvre, vous n’avez le droit de
distribuer votre création que sous une licence identique ou similaire à celle-ci.
Pour toute demande de collaboration, d'utilisation commerciale ou de publication de ce support ou d'un dérivé de celui-ci sous une
licence incompatible, contacter l'auteur via les contacts indiqués sur le site http://www.noelmace.com. Vous êtes par ailleurs
vivement encouragé (sans obligation légale) à communiquer avec celui-ci si vous réalisez une œuvre dérivée ou toute amélioration
de ce support.

Mais conteúdo relacionado

Mais procurados

Java - JDBC - 2 - Intructions SQL
Java - JDBC - 2 - Intructions SQLJava - JDBC - 2 - Intructions SQL
Java - JDBC - 2 - Intructions SQLNoël
 
Presentation Tomcat Load Balancer
Presentation Tomcat Load BalancerPresentation Tomcat Load Balancer
Presentation Tomcat Load Balancertarkaus
 
Presentation JEE et son écossystéme
Presentation JEE et son écossystémePresentation JEE et son écossystéme
Presentation JEE et son écossystémeAlgeria JUG
 
Joomla : AcyMailing et ElasticEmail
Joomla : AcyMailing et ElasticEmailJoomla : AcyMailing et ElasticEmail
Joomla : AcyMailing et ElasticEmailMarc DECHEVRE
 
20111006 bonnes pratiques-gi_g_v1
20111006 bonnes pratiques-gi_g_v120111006 bonnes pratiques-gi_g_v1
20111006 bonnes pratiques-gi_g_v1Gilles Guirand
 
Joomla : Akeeba Backup et Amazon S3
Joomla : Akeeba Backup et Amazon S3Joomla : Akeeba Backup et Amazon S3
Joomla : Akeeba Backup et Amazon S3Marc DECHEVRE
 
TD : 12 Logiciels libres pour contruire vos sites web
TD : 12 Logiciels libres pour contruire vos sites webTD : 12 Logiciels libres pour contruire vos sites web
TD : 12 Logiciels libres pour contruire vos sites webStéphane Rouilly
 
Bâtir son site a l'aide de wordpress
Bâtir son site a l'aide de wordpressBâtir son site a l'aide de wordpress
Bâtir son site a l'aide de wordpressFrédéric Caron
 
Joomla : AcyMailing et ElasticEmail (version 2019)
Joomla : AcyMailing et ElasticEmail (version 2019)Joomla : AcyMailing et ElasticEmail (version 2019)
Joomla : AcyMailing et ElasticEmail (version 2019)Marc DECHEVRE
 
les servlets-java EE
les  servlets-java EEles  servlets-java EE
les servlets-java EEYassine Badri
 
Jsf 110530152515-phpapp01
Jsf 110530152515-phpapp01Jsf 110530152515-phpapp01
Jsf 110530152515-phpapp01Eric Bourdet
 
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs WebUne visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs WebFrédéric Harper
 
Introductions Aux Servlets
Introductions Aux ServletsIntroductions Aux Servlets
Introductions Aux ServletsFrançois Charoy
 

Mais procurados (20)

Java - JDBC - 2 - Intructions SQL
Java - JDBC - 2 - Intructions SQLJava - JDBC - 2 - Intructions SQL
Java - JDBC - 2 - Intructions SQL
 
Presentation Tomcat Load Balancer
Presentation Tomcat Load BalancerPresentation Tomcat Load Balancer
Presentation Tomcat Load Balancer
 
Maven
MavenMaven
Maven
 
Presentation JEE et son écossystéme
Presentation JEE et son écossystémePresentation JEE et son écossystéme
Presentation JEE et son écossystéme
 
Joomla : AcyMailing et ElasticEmail
Joomla : AcyMailing et ElasticEmailJoomla : AcyMailing et ElasticEmail
Joomla : AcyMailing et ElasticEmail
 
Introduction à Laravel
Introduction à LaravelIntroduction à Laravel
Introduction à Laravel
 
20111006 bonnes pratiques-gi_g_v1
20111006 bonnes pratiques-gi_g_v120111006 bonnes pratiques-gi_g_v1
20111006 bonnes pratiques-gi_g_v1
 
Joomla : Akeeba Backup et Amazon S3
Joomla : Akeeba Backup et Amazon S3Joomla : Akeeba Backup et Amazon S3
Joomla : Akeeba Backup et Amazon S3
 
TD : 12 Logiciels libres pour contruire vos sites web
TD : 12 Logiciels libres pour contruire vos sites webTD : 12 Logiciels libres pour contruire vos sites web
TD : 12 Logiciels libres pour contruire vos sites web
 
Bâtir son site a l'aide de wordpress
Bâtir son site a l'aide de wordpressBâtir son site a l'aide de wordpress
Bâtir son site a l'aide de wordpress
 
Joomla : AcyMailing et ElasticEmail (version 2019)
Joomla : AcyMailing et ElasticEmail (version 2019)Joomla : AcyMailing et ElasticEmail (version 2019)
Joomla : AcyMailing et ElasticEmail (version 2019)
 
Drupal Performance
Drupal PerformanceDrupal Performance
Drupal Performance
 
Les Servlets et JSP
Les Servlets et JSPLes Servlets et JSP
Les Servlets et JSP
 
Installation open erp-sous-windows1
Installation open erp-sous-windows1Installation open erp-sous-windows1
Installation open erp-sous-windows1
 
les servlets-java EE
les  servlets-java EEles  servlets-java EE
les servlets-java EE
 
Jsp
JspJsp
Jsp
 
Jsf 110530152515-phpapp01
Jsf 110530152515-phpapp01Jsf 110530152515-phpapp01
Jsf 110530152515-phpapp01
 
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs WebUne visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
Une visite guidée d’Internet Explorer 9 et HTML5 pour les développeurs Web
 
Introductions Aux Servlets
Introductions Aux ServletsIntroductions Aux Servlets
Introductions Aux Servlets
 
Mpdf 5
Mpdf 5Mpdf 5
Mpdf 5
 

Destaque

Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Ryan Cuprak
 
Java EE 7 - Into the Cloud
Java EE 7 - Into the CloudJava EE 7 - Into the Cloud
Java EE 7 - Into the CloudMarkus Eisele
 
J2ee (java ee) design patterns and architecture
J2ee (java ee) design patterns and architectureJ2ee (java ee) design patterns and architecture
J2ee (java ee) design patterns and architectureinTwentyEight Minutes
 
Reusing Existing Java EE Applications from SOA Suite 11g
Reusing Existing Java EE Applications from SOA Suite 11gReusing Existing Java EE Applications from SOA Suite 11g
Reusing Existing Java EE Applications from SOA Suite 11gGuido Schmutz
 
Java EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) TechnologyJava EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) TechnologySivakumar Thyagarajan
 
Vaadin with Java EE 7
Vaadin with Java EE 7Vaadin with Java EE 7
Vaadin with Java EE 7Peter Lehto
 
Développement d'applications pour la plateforme Java EE
Développement d'applications pour la plateforme Java EEDéveloppement d'applications pour la plateforme Java EE
Développement d'applications pour la plateforme Java EESabri Bouchlema
 
Introduction to java ee
Introduction to java eeIntroduction to java ee
Introduction to java eeRanjan Kumar
 
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014Arun Gupta
 
Java EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
Java EE 7: Developing for the Cloud at Geecon, JEEConf, JohannesburgJava EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
Java EE 7: Developing for the Cloud at Geecon, JEEConf, JohannesburgArun Gupta
 
J2ee (java ee) tutorial for beginners
J2ee (java ee) tutorial for beginnersJ2ee (java ee) tutorial for beginners
J2ee (java ee) tutorial for beginnersinTwentyEight Minutes
 
Java EE microservices architecture - evolving the monolith
Java EE microservices architecture - evolving the monolithJava EE microservices architecture - evolving the monolith
Java EE microservices architecture - evolving the monolithMarkus Eisele
 
Java EE vs Spring Framework
Java  EE vs Spring Framework Java  EE vs Spring Framework
Java EE vs Spring Framework Rohit Kelapure
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Ryan Cuprak
 
Java EE and Spring Side-by-Side
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-SideReza Rahman
 
Nine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youNine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youMarkus Eisele
 
Modern web application development with java ee 7
Modern web application development with java ee 7Modern web application development with java ee 7
Modern web application development with java ee 7Shekhar Gulati
 
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Matt Raible
 
Alphorm.com Support Formation Hacking & Sécurité Expert Vulnérabilités Web
Alphorm.com Support Formation Hacking & Sécurité Expert Vulnérabilités WebAlphorm.com Support Formation Hacking & Sécurité Expert Vulnérabilités Web
Alphorm.com Support Formation Hacking & Sécurité Expert Vulnérabilités WebAlphorm
 
Alphorm.com Support de la Formation Les Sciences Forensiques : L’investigati...
Alphorm.com Support de la Formation Les Sciences Forensiques  : L’investigati...Alphorm.com Support de la Formation Les Sciences Forensiques  : L’investigati...
Alphorm.com Support de la Formation Les Sciences Forensiques : L’investigati...Alphorm
 

Destaque (20)

Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
 
Java EE 7 - Into the Cloud
Java EE 7 - Into the CloudJava EE 7 - Into the Cloud
Java EE 7 - Into the Cloud
 
J2ee (java ee) design patterns and architecture
J2ee (java ee) design patterns and architectureJ2ee (java ee) design patterns and architecture
J2ee (java ee) design patterns and architecture
 
Reusing Existing Java EE Applications from SOA Suite 11g
Reusing Existing Java EE Applications from SOA Suite 11gReusing Existing Java EE Applications from SOA Suite 11g
Reusing Existing Java EE Applications from SOA Suite 11g
 
Java EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) TechnologyJava EE Connector Architecture 1.6 (JSR 322) Technology
Java EE Connector Architecture 1.6 (JSR 322) Technology
 
Vaadin with Java EE 7
Vaadin with Java EE 7Vaadin with Java EE 7
Vaadin with Java EE 7
 
Développement d'applications pour la plateforme Java EE
Développement d'applications pour la plateforme Java EEDéveloppement d'applications pour la plateforme Java EE
Développement d'applications pour la plateforme Java EE
 
Introduction to java ee
Introduction to java eeIntroduction to java ee
Introduction to java ee
 
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
Lessons Learned from Real-World Deployments of Java EE 7 at JavaOne 2014
 
Java EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
Java EE 7: Developing for the Cloud at Geecon, JEEConf, JohannesburgJava EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
Java EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
 
J2ee (java ee) tutorial for beginners
J2ee (java ee) tutorial for beginnersJ2ee (java ee) tutorial for beginners
J2ee (java ee) tutorial for beginners
 
Java EE microservices architecture - evolving the monolith
Java EE microservices architecture - evolving the monolithJava EE microservices architecture - evolving the monolith
Java EE microservices architecture - evolving the monolith
 
Java EE vs Spring Framework
Java  EE vs Spring Framework Java  EE vs Spring Framework
Java EE vs Spring Framework
 
Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]Top 50 java ee 7 best practices [con5669]
Top 50 java ee 7 best practices [con5669]
 
Java EE and Spring Side-by-Side
Java EE and Spring Side-by-SideJava EE and Spring Side-by-Side
Java EE and Spring Side-by-Side
 
Nine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take youNine Neins - where Java EE will never take you
Nine Neins - where Java EE will never take you
 
Modern web application development with java ee 7
Modern web application development with java ee 7Modern web application development with java ee 7
Modern web application development with java ee 7
 
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
Java Web Application Security with Java EE, Spring Security and Apache Shiro ...
 
Alphorm.com Support Formation Hacking & Sécurité Expert Vulnérabilités Web
Alphorm.com Support Formation Hacking & Sécurité Expert Vulnérabilités WebAlphorm.com Support Formation Hacking & Sécurité Expert Vulnérabilités Web
Alphorm.com Support Formation Hacking & Sécurité Expert Vulnérabilités Web
 
Alphorm.com Support de la Formation Les Sciences Forensiques : L’investigati...
Alphorm.com Support de la Formation Les Sciences Forensiques  : L’investigati...Alphorm.com Support de la Formation Les Sciences Forensiques  : L’investigati...
Alphorm.com Support de la Formation Les Sciences Forensiques : L’investigati...
 

Semelhante a Java - JEE - servlets

Java - JDBC - 3 - meta données
Java - JDBC - 3 - meta donnéesJava - JDBC - 3 - meta données
Java - JDBC - 3 - meta donnéesNoël
 
Java EE _ Servlet et vue (1).pdf
Java EE _ Servlet et vue (1).pdfJava EE _ Servlet et vue (1).pdf
Java EE _ Servlet et vue (1).pdfColombieColombie
 
Java - Exceptions
Java - ExceptionsJava - Exceptions
Java - ExceptionsNoël
 
Les Servlets, MVC en pratique Les technologies JSP Les EL et OI
Les Servlets, MVC en pratique Les technologies JSP Les EL et OILes Servlets, MVC en pratique Les technologies JSP Les EL et OI
Les Servlets, MVC en pratique Les technologies JSP Les EL et OIHAMIDGARMANI
 
JEE_chapitre 1.pdf
JEE_chapitre 1.pdfJEE_chapitre 1.pdf
JEE_chapitre 1.pdfiyadamri
 
Codedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript
Codedarmor 2012 - 06/03 - HTML5, CSS3 et JavascriptCodedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript
Codedarmor 2012 - 06/03 - HTML5, CSS3 et Javascriptcodedarmor
 
cours j2ee -présentation
cours  j2ee -présentationcours  j2ee -présentation
cours j2ee -présentationYassine Badri
 
ENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
ENIB cours CAI Web - Séance 3 - JSP/Servlet - CoursENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
ENIB cours CAI Web - Séance 3 - JSP/Servlet - CoursHoracio Gonzalez
 
Cours php & Mysql - 3éme partie
Cours php & Mysql - 3éme partieCours php & Mysql - 3éme partie
Cours php & Mysql - 3éme partiekadzaki
 
eServices-Tp1: Web Services
eServices-Tp1: Web ServiceseServices-Tp1: Web Services
eServices-Tp1: Web ServicesLilia Sfaxi
 
Plugiciel Oracle pour Open ModelSphere
Plugiciel Oracle pour Open ModelSpherePlugiciel Oracle pour Open ModelSphere
Plugiciel Oracle pour Open ModelSpheremodelspherepro
 
Atelier : Développement rapide d&rsquo;une application basée surXWiki
Atelier : Développement rapide d&rsquo;une application basée surXWikiAtelier : Développement rapide d&rsquo;une application basée surXWiki
Atelier : Développement rapide d&rsquo;une application basée surXWikiKorteby Farouk
 
Cours php & Mysql - 1ére partie
Cours php & Mysql - 1ére partieCours php & Mysql - 1ére partie
Cours php & Mysql - 1ére partiekadzaki
 
Jug algeria x wiki-atelier
Jug algeria x wiki-atelierJug algeria x wiki-atelier
Jug algeria x wiki-atelierAlgeria JUG
 

Semelhante a Java - JEE - servlets (20)

Java - JDBC - 3 - meta données
Java - JDBC - 3 - meta donnéesJava - JDBC - 3 - meta données
Java - JDBC - 3 - meta données
 
Java EE _ Servlet et vue (1).pdf
Java EE _ Servlet et vue (1).pdfJava EE _ Servlet et vue (1).pdf
Java EE _ Servlet et vue (1).pdf
 
Java - Exceptions
Java - ExceptionsJava - Exceptions
Java - Exceptions
 
Support JEE Servlet Jsp MVC M.Youssfi
Support JEE Servlet Jsp MVC M.YoussfiSupport JEE Servlet Jsp MVC M.Youssfi
Support JEE Servlet Jsp MVC M.Youssfi
 
Les Servlets, MVC en pratique Les technologies JSP Les EL et OI
Les Servlets, MVC en pratique Les technologies JSP Les EL et OILes Servlets, MVC en pratique Les technologies JSP Les EL et OI
Les Servlets, MVC en pratique Les technologies JSP Les EL et OI
 
Rapport tp3 j2ee
Rapport tp3 j2eeRapport tp3 j2ee
Rapport tp3 j2ee
 
JEE_chapitre 1.pdf
JEE_chapitre 1.pdfJEE_chapitre 1.pdf
JEE_chapitre 1.pdf
 
Services rest & jersey
Services rest & jerseyServices rest & jersey
Services rest & jersey
 
Codedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript
Codedarmor 2012 - 06/03 - HTML5, CSS3 et JavascriptCodedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript
Codedarmor 2012 - 06/03 - HTML5, CSS3 et Javascript
 
cours j2ee -présentation
cours  j2ee -présentationcours  j2ee -présentation
cours j2ee -présentation
 
ENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
ENIB cours CAI Web - Séance 3 - JSP/Servlet - CoursENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
ENIB cours CAI Web - Séance 3 - JSP/Servlet - Cours
 
Cours php & Mysql - 3éme partie
Cours php & Mysql - 3éme partieCours php & Mysql - 3éme partie
Cours php & Mysql - 3éme partie
 
eServices-Tp1: Web Services
eServices-Tp1: Web ServiceseServices-Tp1: Web Services
eServices-Tp1: Web Services
 
Plugiciel Oracle pour Open ModelSphere
Plugiciel Oracle pour Open ModelSpherePlugiciel Oracle pour Open ModelSphere
Plugiciel Oracle pour Open ModelSphere
 
Atelier : Développement rapide d&rsquo;une application basée surXWiki
Atelier : Développement rapide d&rsquo;une application basée surXWikiAtelier : Développement rapide d&rsquo;une application basée surXWiki
Atelier : Développement rapide d&rsquo;une application basée surXWiki
 
Servlets et JSP
Servlets et JSPServlets et JSP
Servlets et JSP
 
Cours php & Mysql - 1ére partie
Cours php & Mysql - 1ére partieCours php & Mysql - 1ére partie
Cours php & Mysql - 1ére partie
 
Introduction à ajax
Introduction à ajaxIntroduction à ajax
Introduction à ajax
 
Jug algeria x wiki-atelier
Jug algeria x wiki-atelierJug algeria x wiki-atelier
Jug algeria x wiki-atelier
 
HTML5, le nouveau buzzword
HTML5, le nouveau buzzwordHTML5, le nouveau buzzword
HTML5, le nouveau buzzword
 

Mais de Noël

LPIC2 12 01 pare-feu et nating
LPIC2 12 01 pare-feu et natingLPIC2 12 01 pare-feu et nating
LPIC2 12 01 pare-feu et natingNoël
 
présentation des services Open Source pour GNU/Linux
présentation des services Open Source pour GNU/Linuxprésentation des services Open Source pour GNU/Linux
présentation des services Open Source pour GNU/LinuxNoël
 
LPIC1 11 02 sécurité système
LPIC1 11 02 sécurité systèmeLPIC1 11 02 sécurité système
LPIC1 11 02 sécurité systèmeNoël
 
LPIC1 11 01 sécurité réseaux
LPIC1 11 01 sécurité réseauxLPIC1 11 01 sécurité réseaux
LPIC1 11 01 sécurité réseauxNoël
 
LPIC1 10 04 anacron
LPIC1 10 04 anacronLPIC1 10 04 anacron
LPIC1 10 04 anacronNoël
 
LPIC1 10 05 at
LPIC1 10 05 atLPIC1 10 05 at
LPIC1 10 05 atNoël
 
LPIC1 10 03 cron
LPIC1 10 03 cronLPIC1 10 03 cron
LPIC1 10 03 cronNoël
 
LPIC1 10 02 temps
LPIC1 10 02 tempsLPIC1 10 02 temps
LPIC1 10 02 tempsNoël
 
LPIC1 10 01 logs
LPIC1 10 01 logsLPIC1 10 01 logs
LPIC1 10 01 logsNoël
 
LPIC1 09 06 kill
LPIC1 09 06 killLPIC1 09 06 kill
LPIC1 09 06 killNoël
 
LPIC1 09 05 priorités
LPIC1 09 05 prioritésLPIC1 09 05 priorités
LPIC1 09 05 prioritésNoël
 
LPIC1 09 04 bg fg
LPIC1 09 04 bg fgLPIC1 09 04 bg fg
LPIC1 09 04 bg fgNoël
 
LPIC1 09 03 top
LPIC1 09 03 topLPIC1 09 03 top
LPIC1 09 03 topNoël
 
LPIC1 09 02 ps
LPIC1 09 02 psLPIC1 09 02 ps
LPIC1 09 02 psNoël
 
LPIC1 09 01 intro
LPIC1 09 01 introLPIC1 09 01 intro
LPIC1 09 01 introNoël
 
LPIC1 08 05 runlevels
LPIC1 08 05 runlevelsLPIC1 08 05 runlevels
LPIC1 08 05 runlevelsNoël
 
LPIC1 08 03 grub2
LPIC1 08 03 grub2LPIC1 08 03 grub2
LPIC1 08 03 grub2Noël
 
LPIC1 08 02 grub legacy
LPIC1 08 02 grub legacyLPIC1 08 02 grub legacy
LPIC1 08 02 grub legacyNoël
 
LPIC1 08 01 démarrage
LPIC1 08 01 démarrageLPIC1 08 01 démarrage
LPIC1 08 01 démarrageNoël
 
LPIC1 07 14 mount
LPIC1 07 14 mountLPIC1 07 14 mount
LPIC1 07 14 mountNoël
 

Mais de Noël (20)

LPIC2 12 01 pare-feu et nating
LPIC2 12 01 pare-feu et natingLPIC2 12 01 pare-feu et nating
LPIC2 12 01 pare-feu et nating
 
présentation des services Open Source pour GNU/Linux
présentation des services Open Source pour GNU/Linuxprésentation des services Open Source pour GNU/Linux
présentation des services Open Source pour GNU/Linux
 
LPIC1 11 02 sécurité système
LPIC1 11 02 sécurité systèmeLPIC1 11 02 sécurité système
LPIC1 11 02 sécurité système
 
LPIC1 11 01 sécurité réseaux
LPIC1 11 01 sécurité réseauxLPIC1 11 01 sécurité réseaux
LPIC1 11 01 sécurité réseaux
 
LPIC1 10 04 anacron
LPIC1 10 04 anacronLPIC1 10 04 anacron
LPIC1 10 04 anacron
 
LPIC1 10 05 at
LPIC1 10 05 atLPIC1 10 05 at
LPIC1 10 05 at
 
LPIC1 10 03 cron
LPIC1 10 03 cronLPIC1 10 03 cron
LPIC1 10 03 cron
 
LPIC1 10 02 temps
LPIC1 10 02 tempsLPIC1 10 02 temps
LPIC1 10 02 temps
 
LPIC1 10 01 logs
LPIC1 10 01 logsLPIC1 10 01 logs
LPIC1 10 01 logs
 
LPIC1 09 06 kill
LPIC1 09 06 killLPIC1 09 06 kill
LPIC1 09 06 kill
 
LPIC1 09 05 priorités
LPIC1 09 05 prioritésLPIC1 09 05 priorités
LPIC1 09 05 priorités
 
LPIC1 09 04 bg fg
LPIC1 09 04 bg fgLPIC1 09 04 bg fg
LPIC1 09 04 bg fg
 
LPIC1 09 03 top
LPIC1 09 03 topLPIC1 09 03 top
LPIC1 09 03 top
 
LPIC1 09 02 ps
LPIC1 09 02 psLPIC1 09 02 ps
LPIC1 09 02 ps
 
LPIC1 09 01 intro
LPIC1 09 01 introLPIC1 09 01 intro
LPIC1 09 01 intro
 
LPIC1 08 05 runlevels
LPIC1 08 05 runlevelsLPIC1 08 05 runlevels
LPIC1 08 05 runlevels
 
LPIC1 08 03 grub2
LPIC1 08 03 grub2LPIC1 08 03 grub2
LPIC1 08 03 grub2
 
LPIC1 08 02 grub legacy
LPIC1 08 02 grub legacyLPIC1 08 02 grub legacy
LPIC1 08 02 grub legacy
 
LPIC1 08 01 démarrage
LPIC1 08 01 démarrageLPIC1 08 01 démarrage
LPIC1 08 01 démarrage
 
LPIC1 07 14 mount
LPIC1 07 14 mountLPIC1 07 14 mount
LPIC1 07 14 mount
 

Java - JEE - servlets

  • 1. Oracle Certified Professional, Java SE 7 Programmer noelmace.com Noël Macé Formateur et Consultant indépendant expert Unix et FOSS http://www.noelmace.com Servlets Java EE Licence Creative Commons Ce(tte) œuvre est mise à disposition selon les termes de la Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 3.0 France.
  • 2. Oracle Certified Professional, Java SE 7 Programmer noelmace.com Plan • Qu'est qu'une servlet • HttpServlet • Requête • Réponse • Exemple
  • 3. Oracle Certified Professional, Java SE 7 Programmer noelmace.com Qu'est qu'une servlet • classe java dérivée de javax.servlet.http.HttpServlet • permet la création dynamique de données  au sain d'un serveur HTTP  le plus souvent au format HTML • exécution coté serveur
  • 4. Oracle Certified Professional, Java SE 7 Programmer noelmace.com HttpServlet • classe mère de toutes les servlets • Méthodes  void doGet(HttpServletRequest request, HttpServletResponse response) • point d'entrée relatif à une requête HTTP GET - <form ... method="GET"> - ou via l'url  void doPost(HttpServletRequest request, HttpServletResponse response) • point d'entrée relatif à une requête HTTP POST - balise <form ... method="POST">
  • 5. Oracle Certified Professional, Java SE 7 Programmer noelmace.com Requête • interface javax.servlet.http.HttpServletRequest • Méthode  String getParameter(String arg0) • permet de récupérer la valeur d'un paramêtre •
  • 6. Oracle Certified Professional, Java SE 7 Programmer noelmace.com Réponse • interface javax.servlet.http.HttpServletResponse • Méthodes  setContentType • spécifie le type MIME de la réponse  java.io.OutputStream getOutputStream • génère un OutputStream permettant l'envoi de données binaires • ex : image JPEG  java.io.PrintWriter getWriter • génère un PrintWrier, permettant l'envoi du texte de réponse • ex : HTML
  • 7. Oracle Certified Professional, Java SE 7 Programmer noelmace.com Exemple public class ServletHelloWorld extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String texte = request.getParameter("test"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.write("<html><head><title>Bienvenue</title></head>" + "<body><h1>Bienvenue</h1>" + "<p>Bonjour " + texte + "</p></body></html>"); } } public class ServletHelloWorld extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String texte = request.getParameter("test"); response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.write("<html><head><title>Bienvenue</title></head>" + "<body><h1>Bienvenue</h1>" + "<p>Bonjour " + texte + "</p></body></html>"); } }
  • 8. Oracle Certified Professional, Java SE 7 Programmer noelmace.com Configuration • web/WEB-INF/web.xml <?xml version="1.0"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>Bienvenue</servlet-name> <servlet-class>com.eteks.test.ServletBienvenue</servlet-class> </servlet> <servlet-mapping> <servlet-name>Bienvenue</servlet-name> <url-pattern>/bienvenue</url-pattern> </servlet-mapping> </web-app> <?xml version="1.0"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>Bienvenue</servlet-name> <servlet-class>com.eteks.test.ServletBienvenue</servlet-class> </servlet> <servlet-mapping> <servlet-name>Bienvenue</servlet-name> <url-pattern>/bienvenue</url-pattern> </servlet-mapping> </web-app>
  • 9. Oracle Certified Professional, Java SE 7 Programmer noelmace.com Ce qu’on a couvert • Génération dynamique de contenu web grâce aux servlets  classes  méthodes  réponse et requète FIN
  • 10. Oracle Certified Professional, Java SE 7 Programmer noelmace.com Licence Ce(tte) œuvre (y compris ses illustrations, sauf mention explicite) est mise à disposition selon les termes de la Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 3.0 France. Pour voir une copie de cette licence, visitez http://creativecommons.org/licenses/by-nc-sa/3.0/fr/ ou écrivez à : Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA. Vous êtes libre de :  partager — reproduire, distribuer et communiquer cette œuvre  remixer — adapter l’œuvre Selon les conditions suivantes :  Attribution — Vous devez clairement indiquer que ce document, ou tout document dérivé de celui, est (issu de) l’œuvre originale de Noël Macé (noelmace.com) (sans suggérer qu'il vous approuve, vous ou votre utilisation de l’œuvre, à moins d'en demander expressément la permission).  Pas d’Utilisation Commerciale — Vous n’avez pas le droit d’utiliser cette œuvre à des fins commerciales (ie. l'intention première ou l'objectif d'obtenir un avantage commercial ou une compensation financière privée). Pour obtenir ce droit, une autorisation explicite de l'auteur est requise.  Partage dans les Mêmes Conditions — Si vous modifiez, transformez ou adaptez cette œuvre, vous n’avez le droit de distribuer votre création que sous une licence identique ou similaire à celle-ci. Pour toute demande de collaboration, d'utilisation commerciale ou de publication de ce support ou d'un dérivé de celui-ci sous une licence incompatible, contacter l'auteur via les contacts indiqués sur le site http://www.noelmace.com. Vous êtes par ailleurs vivement encouragé (sans obligation légale) à communiquer avec celui-ci si vous réalisez une œuvre dérivée ou toute amélioration de ce support.