09_Servlet - CSI 3540 Structures techniques et normes du...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSI 3540 Structures, techniques et normes du Web Tuesday, February 9, 2010 Objectif: • Introduction à la programmation côté serveur • Introduction aux Servlets Lectures: • Web Technologies (2007) § 6 Pages 323–350 Programmation côté serveur : Servlets Tuesday, February 9, 2010 Plan 1. Session 2. Témoins de connexion (cookies) 3. Réécritures d’URL Tuesday, February 9, 2010 Servlet Internet Client Serveur Serveur W eb Servlet Requête HTTP Réponse HTTP Tuesday, February 9, 2010 Résumé • Un Servlet peut être vu comme une extension d’un serveur HTTP • Un Servlet est une sous-classe de HttpServlet • Cycle de vie : init (), service (), destroy () • doGet() et doPost() , HttpServletRequest et HttpServletResponse • Technologie sous-jacente des pages JSP Tuesday, February 9, 2010 init() public void init() throws UnavailableException { String filename = "/data/words.csv "; ServletContext context = getServletContext() ; InputStream is = context.getResourceAsStream( filename ) ; if ( is != null ) { try { InputStreamReader isr = new InputStreamReader( is ); BufferedReader reader = new BufferedReader( isr ); StringBuffer buffer = new StringBuffer(); String line; while ( ( line = reader.readLine() ) != null ) { buffer.append( line ); } i s . c l o s e ( ) ; dict = buffer.toString(); } catch ( IOException e ) { throw new UnavailableException( "error while reading dictionary" ); } } } Tuesday, February 9, 2010 import java.io. *; import javax.servlet. * ; import javax.servlet.http. * ; import java.util.Date ; public class GetTime extends HttpServlet { public void doGet ( HttpServletRequest requete , HttpServletResponse reponse ) throws ServletException , IOException { reponse.setContentType( "text/html; charset=\"UTF-8\"" ); PrintWriter doc = reponse.getWriter() ; doc.println( "<!DOCTYPE html" ) ; // ... doc.println( "</html>" ); d o c . c l o s e ( ) ; } } Tuesday, February 9, 2010 Session Témoins Tuesday, February 9, 2010 Tuesday, February 9, 2010 Sessions • Fréquemment, les applications Web recueillent les informations à l’aide d’une suite de pages et donc de plusieurs requêtes HTTP (pensez au panier d’achats virtuel) • Problème : comment établir des relations entre les différentes requêtes qui forment une même «session» ? Plusieurs requêtes peuvent provenir d’une même station de travail Le même usager pourrait même avoir deux sessions concourantes Tuesday, February 9, 2010 Sessions (haut niveau) • Un identifcateur est ajouté aux requêtes HTTP : Session ID • Le serveur assignera un identifcateur de session à toute requête qui n’en a pas • L’identifcateur sera retourné dans les messages réponse HTTP • L’identifcateur Fera partie des requêtes subséquentes (caché et transmis par le client ) Tuesday, February 9, 2010 Sessions Tuesday, February 9, 2010 Session et Servlets • Avec les Servlets, un objet réalisant l’interface Session modélise une session HttpSession session = requete.getSession() ; Tuesday, February 9, 2010 Application GetCount...
View Full Document

This note was uploaded on 06/07/2010 for the course CSI ITI1520 taught by Professor Marcelturcotte during the Spring '10 term at University of Ottawa.

Page1 / 50

09_Servlet - CSI 3540 Structures techniques et normes du...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online