Download - Le tecnologie software Internet
![Page 1: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/1.jpg)
B2 TecnSoft Internet Paolo Salvaneschi 1
B2_1 V1.7
Le tecnologie software InternetStandard aperti / Sun Java
Applicazioni Internet B
Paolo Salvaneschi
Università di BergamoFacoltà di Ingegneria
Il contenuto del documento è liberamente utilizzabile dagli studenti, per studio personale e per supporto a lezioni universitarie.Ogni altro uso è riservato, e deve essere preventivamente autorizzato dall’ autore.
Sono graditi commenti o suggerimenti per il miglioramento del materiale
![Page 2: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/2.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 2
• Tecnologie (standard aperti + Sun Java)– Pagine Web statiche (HTML,CSS)– Scripting lato client, JavaScript (DHTML)– Java Applet– CGI– Java Servlet– Java Server Pages– Connessione con i Data Base
INDICE
![Page 3: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/3.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 3
• Tecnologie• Nomenclatura:
Tecnologie (standard aperti + Sun Java)
Linguaggio es. Java
Tecnologia es. JSP
Esempio di Strumento es. Tomcat
![Page 4: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/4.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 4
• Pagine Web statiche (HTML,CSS)• Pagine Web dinamiche lato Client
– Scripting lato client, JavaScript (DHTML)– Java Applet
• Pagine Web dinamiche lato Server– CGI– Servlet, JSP– Connessione con i Data Base
Tecnologie (standard aperti + Sun Java)
![Page 5: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/5.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 5
Pagine Web statiche (HTML,CSS)
BrowserHTML
CSS
ClientServer
HTTPD
Server
Data base
Sistema Informativo
HTTP
Apache Microsoft Internet ExplorerMozilla Firefox
![Page 6: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/6.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 6
Pagine Web statiche (HTML,CSS)
BrowserHTML
CSS
ClientServer
HTTPD
Richiesta HTTPGET /paginaxx.htm HTTP/1.1…
HTTP/1.1 200…<html><head><title>Paginaxx</title>...</body></html>
<html> <body><a href=“http://www.pippo.it/paginaxx.htm”>chiedi pagina xx</a></body></html>
File Paginaxx.htm
Risposta HTTP
http://www.pippo.it:80/….
![Page 7: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/7.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 7
http://httpd.apache.org
Pagine Web statiche (HTML,CSS)
![Page 8: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/8.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 8
• Pagine Web statiche– Server di documenti ipermediali– Distribuzione di documenti codificati in
HTML– Separazione della struttura dalla
presentazione (CSS)
Pagine Web statiche (HTML,CSS)
![Page 9: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/9.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 9
Pagine Web statiche (HTML,CSS)
<html>
<head><title>La prima pagina Web di Mario Rossi</title><link type="text/css"
rel="Stylesheet" href="Es2_css_esterno.css"></head>
<body><h1>Home page di Mario Rossi</h1><p>Questa è la mia prima pagina in HTML.</p><h1>Intestazione di primo livello</h1><h2>Intestazione di secondo livello</h2><h3>Intestazione di terzo livello</h3>…
h1{font-family: Arial;font-size: 20pt;color: blue;font-weight: bold;}
CSS
![Page 10: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/10.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 10
Scripting lato client, JavaScript (DHTML)
BrowserHTML
CSSJavaScript
ClientServer
HTTPD
Server
Data base
Sistema Informativo
HTTP
Apache Microsoft Internet ExplorerMozilla Firefox
![Page 11: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/11.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 11
• Pagine Web dinamiche (DHTML)• Insieme di tecnologie che permettono di
modificare le pagine HTML caricate nel browser senza interagire con il server– Es. modifica della formattazione a seguito
di interazione con l’utente– Es. controllo dell’input
Scripting lato client, JavaScript (DHTML)
![Page 12: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/12.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 12
• HTML+CSS+Java Script– Integrazione di procedure interpretate
nella pagina HTML ; Esecuzione lato client– Gestione eventi ed interazione locale con
l’utente– Definizione oggetti e attributi (DOM
Document Object Model) componenti la pagina e modificabilità da programma
Scripting lato client, JavaScript (DHTML)
![Page 13: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/13.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 13
<HTML><HEAD><TITLE>javascript</TITLE>
<SCRIPT language="JavaScript">function presenta(){alert("Sei mai stato in cima all'Adamello?")}</SCRIPT>
</HEAD>
<BODY bgcolor="#FFFF00"><BR><BR><BR><BR><IMG src="..\immagini\ada_sal.jpeg" onmouseover="presenta()">
</BODY></HTML>
Scripting lato client, JavaScript (DHTML)
Gestore degli eventi
Scripting
![Page 14: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/14.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 14
<HEAD><SCRIPT language="JavaScript">function uno(){document.all.container1.style.visibility="visible";document.all.container2.style.visibility="hidden";}function due(){document.all.container1.style.visibility="hidden";document.all.container2.style.visibility="visible";}</SCRIPT>
…
Scripting lato client, JavaScript (DHTML)
DOM
Scripting
![Page 15: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/15.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 15
Scripting lato client, JavaScript (DHTML)
…<STYLE type="text/css">#container1 {
position:absolute;top: 2in;left: 2in;width: 2in;visibility: visible;}
#container2 {position:absolute;top: 2in;left: 2in;width: 2in;visibility: hidden;}
</STYLE></HEAD>
<BODY><DIV id="container1">
<IMG src="..\immagini\ada_sal.jpeg"width="300" height="300" onmouseover="due()">
<P><b>l'Adamello da sud</b></P></DIV><DIV id="container2">
<IMG src="..\immagini\ada_lobbie.jpeg"width="300" height="300" onmouseout="uno()">
<P><b>Le Lobbie da Nord</b></P></DIV>
</BODY></HTML>
CSS
Eventi
![Page 16: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/16.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 16
Java Applet
BrowserHTML
CSSApplet Java
ClientServer
HTTPD
Server
Data base
Sistema Informativo
HTTP
Apache Microsoft Internet ExplorerMozilla Firefox(Java Virtual Machine)
![Page 17: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/17.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 17
<HTML><HEAD><TITLE>A Clock (1.6)</TITLE></HEAD><BODY> <h1>A Clock (1.6)</h1><applet code="Clock.class" width="170" height="150"><param name="bgcolor" value="000000"><param name="fgcolor1" value="ff0000"><param name="fgcolor2" value="ff00ff"></applet></BODY></HTML>
Inserimento oggetto
![Page 18: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/18.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 18
CGI
Browser
ClientServer
HTTPD
Server
Data base
Sistema Informativo
HTTP
Apache Microsoft Internet ExplorerMozilla Firefox
Linguaggio di
Programmaz.C, Java, Perl
…
CGI
![Page 19: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/19.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 19
CGI
http://www.pippo.itSetup del Web server:c:\ilmioserverè la directory radice
Quando il server riceve unarichiesta corrispondente all’URLhttp://www.pippo.itcerca un file di default nella directory radice(index.html, index.htm, default.html, default.htm).
Ad ogni richiesta di pagina (http://www.pippo.it/paginax.htm)Il server trasmette la pagina.
![Page 20: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/20.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 20
CGI
Nella directory radice è creata una directory cgi-bin.
Quando il server riceve una richiesta di un file in cgi-bin
non serve il filema lo manda in esecuzione eserve l’output dell’esecuzione.
![Page 21: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/21.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 21
CGI
#include <stdio.h>int main(){ printf("Content-type: text/html\n\n"); printf("<html>\n"); printf("<body>\n"); printf("<h1>Hello there!</h1>\n"); printf("</body>\n"); printf("</html>\n"); return 0;
}
HTTP/1.1 200…Content-type: text/html...
<html> <body><h1>Hello there!</h1></body></html>
<html> <body><a href=“http://www.pippo.it/ilmioserver/cgi-bin/esempio.cgi”>attiva cgi</a></body></html>
![Page 22: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/22.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 22
CGI
#include <stdio.h>int main(){ Il programma può includerequalsiasi procedurache accede a banche dati o interagisce con il sistema informativo esistentereturn 0;
}
…
<html> <body><a href=“http://www.pippo.it/ilmioserver/cgi-bin/esempio.cgi”>attiva cgi</a></body></html>
![Page 23: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/23.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 23
• Invio di dati– Metodo GET– Nomi e valori sono appesi alla URL
– Metodo POST – Nomi e valori sono nel corpo del messaggio
CGI
http://nome.server/cgi.bin/programma?nome=valore&nome=valore…
nome=valore&nome=valore…
![Page 24: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/24.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 24
…<body><form method="POST"action="http://nome.server/cgi.bin/programma">………………………….</form></body>…
CGI
• Raccolta dati da client via form• Method (POST | GET) (case insensitive):
identifica il metodo HTTP utilizzato per trasmettere i dati della form
• Action: indirizza l’applicazione che elabora i dati
![Page 25: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/25.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 25
• Variabili di ambiente– Il programma attivato
può accedere ad un insieme di varabili di ambiente
CGI
•…•CONTENT_LENGTH •CONTENT_TYPE •GATEWAY_INTERFACE •HTTP_ACCEPT •HTTP_USER_AGENT •PATH_INFO •PATH_TRANSLATED •QUERY_STRING •REMOTE_ADDR •REMOTE_HOST •REMOTE_IDENT •REMOTE_USER •REQUEST_METHOD •SCRIPT_NAME •SERVER_NAME •SERVER_PORT •…
Contiene il metodo usato: GET o POST
Contiene i dati passati dal clientcon il metodo GET
![Page 26: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/26.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 26
• Limiti– Ogni richiesta al server via CGI genera un
processo che termina a fine elaborazione– Se il programma attivato via CGI contiene un
accesso a DataBase, ogni volta sarà aperta e chiusa una connessione al DBMS
– Utilizzo di risorse elevato problemi di scalabilità (es. applicazione B2C)
CGI
![Page 27: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/27.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 27
Tecnologie (standard aperti + Sun Java)
BrowserHTML
CSSJavaScript
Java Applet
ClientServer
HTTPD
Server
Data base
Sistema Informativo
HTTP
Apache Microsoft Internet ExplorerMozilla Firefox
Linguaggio di
Programmaz.C, Java, Perl
…
CGI
Integrazione delle tecnologie
![Page 28: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/28.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 28
Java Servlet
Browser
ClientServer
HTTPD
Server
Data base
Sistema Informativo
HTTP
Apache Microsoft Internet ExplorerMozilla Firefox
JavaServlet
Tomcat
Application Server
![Page 29: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/29.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 29
http://jakarta.apache.org
Tomcat
Java Servlet
![Page 30: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/30.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 30
Java Servlet
• Servlet– Oggetti Java particolari che sono caricati ed
eseguiti dal web server che li utilizza come proprie estensioni.
– Il web server mette a disposizione delle Servletun “container” che si occupa della gestione dell’ambiente all’interno delle quali le servletgirano.
– Il “container” passa i dati dal client verso le servlet e viceversa.
![Page 31: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/31.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 31
Java Servlet
• Package javax.servlet– Package di base delle Servlet API– Contiene le classi per definire Servlet standard
indipendenti dal protocollo.– Una Servlet generica è una classe definita a
partire dall’interfaccia Servlet contenuta all’interno del package javax.servlet.
![Page 32: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/32.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 32
Java Servlet
• Package javax.servlet.http– Le classi del package estendono le funzionalità
di base di una servlet supportando tutte le caratteristiche della trasmissione di dati con protocollo http compresi cookies
![Page 33: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/33.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 33
Java Servlet
• Ciclo di vita di una Servlet– Una servlet è caricata e inizializzata dal web
server al momento della prima richiesta http da parte di un client o al momento dell’avvio del servizio.
– All’inizializzazione la servlet può, se il caso, aprire una connessione con un DataBase (connessione che resta aperta per servire piùrichieste del client).
![Page 34: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/34.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 34
Java Servlet
• Ciclo di vita di una Servlet– La servlet esegue le richieste del client.
Per ogni richiesta è creato un thread.
– La servlet rilascia le risorse ed è distrutta
![Page 35: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/35.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 35
HelloWorldServlet.java….import javax.servlet.* ;import javax.servlet.http.* ;public class HelloWorldServlet extends HttpServlet{
public void service (HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{
res.setContentType(“text/html”);ServletOutputStream out = res.getOutputStream();out.println(“<html>”);out.println(“<head><title>Hello World</title></head>”);out.println(“<body>”);out.println(“<h1>Hello World</h1>”);out.println(“</body></html>”);
}}
Metodo invocato al momento dell’ arrivo di unarichiesta da parte di un client
Java Servlet
![Page 36: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/36.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 36
Java Servlet
• Application server
…………….Sun MicrosystemsSun ONEIBMWebsphereBEAWebLogicOpen SourceTomcat
![Page 37: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/37.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 37
Java Server Pages
Browser
ClientServer
HTTPD
Server
Data base
Sistema Informativo
HTTP
Apache Microsoft Internet ExplorerMozilla Firefox
JavaJSP
Tomcat
Application Server
![Page 38: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/38.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 38
Java Server Pages
• Java Server Pages (JSP)– Pagina di testo HTML che include codice java– Pagina dinamica che è eseguita lato server e
restituisce HTML al client
![Page 39: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/39.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 39
Java Server Pages
• Scripting lato client– Scopo: rendere dinamica l’interfaccia utente
– Cambiare a seguito di eventi la presentazione– Gestire l’input dell’utente– …
• Scripting lato server– Scopo: connettersi a programmi e basi dati e
modificare di conseguenza la pagina inviata
![Page 40: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/40.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 40
Java Server Pages
• Java Server Pages (JSP)– Il server utilizza la pagina JSP come una servlet– Al momento del primo accesso la pagina JSP è
trasformata in un file Java e compilata ottenendo una classe Java che rappresenta una servlet di tipo HttpServlet che crea una pagina html e la invia al client.
![Page 41: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/41.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 41
Java Server Pages
• Java Server Pages (JSP)– Possibile integrazione tra servlet e JSP: il client
invia una richiesta ad una servlet che invia gli oggetti prodotti ad una JSP la quale genera l’HTML e lo invia• JSP: View• Servlet: Controller• Componenti Java: Model
![Page 42: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/42.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 42
esempio1.jsp
<html><body><h1> Informazioni sulla richiesta http </h1><br>Metodo richiesto : <%= request.getMethod() %><br>URI : <%= request.getRequestURI() %><br>Protocollo : <%= request.getProtocol() %><br><body></html>
Espressioni :iniziano con la sequenza dicaratteri “<%=” e terminano con la sequenza “%>”Utilizzate per aggiungere alla risposta httpil risultato dell’esecuzione di un’espressione di scripting
Java Server Pages
![Page 43: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/43.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 43
Esempio2.jsp<html>
<body><% for(int i=0; i<10; i++) {
if(i%2==0) {%>
<h1>Pari</h1><% } else { %>
<h2>Dispari</h2><%
}}
%><body>
</html>
Scriptlet:iniziano con la sequenza “<%”, terminano con la sequenza “%>“
Possibilità si spezzare il codice Java contenuto all’ interno delle scriptlet per darmodo al programmatore di non dover fonderetag html all’interno del sorgente Java.
Java Server Pages
![Page 44: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/44.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 44
Server Side Include (.shtml)
• Apache SSI (Server Side Includes)– Pagina di testo HTML che include direttive
valutate dal server– Lo script è eseguito sul server alla richiesta
della pagina e modifica dinamicamente la pagina che è trasmessa al client
– Utile per inserire parti dinamiche limitate (altrimenti si utilizza CGI o JSP)
![Page 45: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/45.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 45
Server Side Include (.shtml)
• Apache SSI (Server Side Includes)– SINTASSI DELLE DIRETTIVE:
<!--#element attribute=value attribute=value ...-->
– Formattato come commento HTML; se il server non è abilitato non lo elabora ma è visibile nel sorgente HTML
– Il file che include le direttive deve avere estensione .shtml
– Esempio: produce la data corrente<!--#echo var="DATE_LOCAL" -->
![Page 46: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/46.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 46
Connessione con i Data Base
ClientServer
HTTPD
Server
Database
JDBC
(ODBC)
SQL
![Page 47: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/47.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 47
Connessione con i Data Base
• ODBC (Open DataBAse Connectivity)– Standard internazionale di accesso a Database
Relazionali• JDBC
– Interfaccia ad oggetti java di accesso a sorgenti di dati
– Connessa ai singoli driver di DataBase attraverso una interfaccia nativa o attraverso un ponte verso ODBC
![Page 48: Le tecnologie software Internet](https://reader036.vdocuments.mx/reader036/viewer/2022071602/613d7694736caf36b75da0a2/html5/thumbnails/48.jpg)
B2 TecnSoft Internet Paolo SalvaneschiB2 TecnSoft Internet Paolo Salvaneschi 48
J2EE