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 ct serveur Introduction aux Servlets Lectures: Web Technologies (2007) 6 Pages 323350 Programmation ct serveur : Servlets Tuesday, February 9, 2010 Plan 1. Session 2. Tmoins de connexion (cookies) 3. Rcritures dURL Tuesday, February 9, 2010 Servlet Internet Client Serveur Serveur W eb Servlet Requte HTTP Rponse HTTP Tuesday, February 9, 2010 Rsum Un Servlet peut tre vu comme une extension dun 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 Tmoins Tuesday, February 9, 2010 Tuesday, February 9, 2010 Sessions Frquemment, les applications Web recueillent les informations laide dune suite de pages et donc de plusieurs requtes HTTP (pensez au panier dachats virtuel) Problme : comment tablir des relations entre les diffrentes requtes qui forment une mme session ? Plusieurs requtes peuvent provenir dune mme station de travail Le mme usager pourrait mme avoir deux sessions concourantes Tuesday, February 9, 2010 Sessions (haut niveau) Un identifcateur est ajout aux requtes HTTP : Session ID Le serveur assignera un identifcateur de session toute requte qui nen a pas Lidentifcateur sera retourn dans les messages rponse HTTP Lidentifcateur Fera partie des requtes subsquentes (cach et transmis par le client ) Tuesday, February 9, 2010 Sessions Tuesday, February 9, 2010 Session et Servlets Avec les Servlets, un objet ralisant linterface Session modlise une session HttpSession session = requete.getSession() ; Tuesday, February 9, 2010 Application GetCount...
View Full Document

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