SlideShare una empresa de Scribd logo
1 de 13
Objetos Implícitos
JSP
Realizado Por:
Paula Castellanos
SESSIONS
● Es un objeto de la clase HttpSession. Nos permite
acceder a la sesión asociada a la petición. A través
de este objeto podemos, entre otras cosas,
guardar objetos que serán accesibles desde
cualquier JSPde la sesión o invalidarla .Para
guardar y recuperar información
usaremos:Objectsession.getAttribute("clave");void
session.setAttribute("clave", Object objeto);Y
para invalidar la sesión: void session.invalidate();
EJEMPLO
<%@ page import="java.io.*,java.util.*" %>
<%
// Get session creation time.
Date createTime = new
Date(session.getCreationTime());
// Get last access time of this web page.
Date lastAccessTime = new
Date(session.getLastAccessedTime());
String title = "Welcome Back to my website";
Integer visitCount = new Integer(0);
String visitCountKey = new
String("visitCount");
String userIDKey = new String("userID");
String userID = new String("ABCD");
// Check if this is new comer on your web page.
if (session.isNew()){
title = "Welcome to my website";
session.setAttribute(visitCountKey,
visitCount);
}
visitCount =
(Integer)session.getAttribute(visitCountKey);
visitCount = visitCount + 1;
userID =
(String)session.getAttribute(userIDKey
);
session.setAttribute(visitCountKey,
visitCount);
%>
<html>
<head>
<title>Session Tracking</title>
● </head>
● <body>
● <center>
● <h1>Session Tracking</h1>
● </center>
● <table border="1" align="center">
● <tr bgcolor="#949494">
● <th>Session info</th>
● <th>Value</th>
● </tr>
● <tr>
● <td>id</td>
● <td><% out.print( session.getId()); %></td>
● </tr>
● <tr>
● <td>Creation Time</td>
● <td><% out.print(createTime); %></td>
● </tr>
● <tr>
● <td>Time of Last Access</td>
● <td><% out.print(lastAccessTime); %></td>
● </tr>
● <tr>
● <td>User ID</td>
● <td><% out.print(userID); %></td>
● </tr>
● <tr>
● <td>Number of visits</td>
● <td><% out.print(visitCount); %></td>
● </tr>
● </table>
● </body>
● </html>
APPLICATION
● Es un objeto de la clase ServletContext .Este
objeto es común para toda la aplicación web
y,entre otras cosas, nos permite almacenar
información que será accesible desde todas las
páginas de la aplicación web, independientemente
de la sesión .Para guardar y recuperar valores:
*Object application.getAttribute("clave");
*void application.setAttribute("clave", Object
objeto);
EJEMPLO
●<%@ page import="java.io.*,java.util.*" %>
●<html>
●<head>
●<title>Application Implicit Object Example</title>
●</head>
●<body>
●<%
● //Comment: This would return null for the first time
● Integer counter= (Integer)application.getAttribute("numberOfVisits");
● if( counter ==null || counter == 0 ){
● //Comment: For the very first Visitor
● counter = 1;
● }else{
● //Comment: For Others
● counter = counter+ 1;
● }
● application.setAttribute("numberOfVisits", counter);
● %>
● <h3>Total number of hits to this Page is: <%= counter%></h3>
● </body>
● </html>
CONFIG
● Es un objeto de la clase ServeletConfig.
Permite acceder a parámetros de
inicialización del Servlet y a su contexto.
EJEMPLO
●<html>
●<head> <title> Config Implicit Object</title>
●</head>
●<body>
●<%
●String sname=config.getServletName();
●out.print("Servlet Name is: "+sname);
●%>
●</body>
●</html>
PAGECONTEXT
● Es un objeto de la clase PageContext. Entre otras
cosas, nos permite almacenar información
localmente a la página .Para guardar y recuperar
valores: Object
pageContext.getAttribute("clave");void
pageContext.setAttribute("clave", Object objeto);
EJEMPLO
● También podemos usar PageContext para almacenar y
recuperar información en sesión y en aplicación:
● Almacenar en contexto de pagina :
PageContext.setAttribute("clave", obj, PageContext. PAGE
_SCOPE);
● PageContext.setAttribute("clave", obj);
● Almacenar en contexto de sesión :
PageContext.setAttribute("clave",obj, Page Context .
SESSION_SCOPE);
● session.setAttribute("clave", objeto);
● Almacenar en contexto de
aplicación:PageContext.setAttribute("clave",obj,PageContext.A
PPLICATION_SCOPE);
● application.setAttribute("clave",objeto);
PAGE
● Es un sinónimo de this, no tiene utilidad en el
estado actual de la especificación.
BIBLIOFRAFIA
● http://rua.ua.es/dspace/bitstream/10045/3300/5/i
ntrojsp.pdf
● http://beginnersbook.com/2013/11/jsp-implicit-
object-application-with-examples/
● http://beginnersbook.com/2013/11/jsp-implicit-
object-application-with-examples/

Más contenido relacionado

Destacado

Componentes de la educaciÓn geogrÁfica
Componentes de la educaciÓn geogrÁfica Componentes de la educaciÓn geogrÁfica
Componentes de la educaciÓn geogrÁfica LI Gómez Glez
 
Don't Quit! Improving Your District's Community Engagement & Communication is...
Don't Quit! Improving Your District's Community Engagement & Communication is...Don't Quit! Improving Your District's Community Engagement & Communication is...
Don't Quit! Improving Your District's Community Engagement & Communication is...Schoolwires, Inc.
 
สรุปผลการดำเนินการจัดซื้อจัดจ้างในรอบเดือน ตุลาคม - ธันวาคม 2558
สรุปผลการดำเนินการจัดซื้อจัดจ้างในรอบเดือน ตุลาคม - ธันวาคม 2558สรุปผลการดำเนินการจัดซื้อจัดจ้างในรอบเดือน ตุลาคม - ธันวาคม 2558
สรุปผลการดำเนินการจัดซื้อจัดจ้างในรอบเดือน ตุลาคม - ธันวาคม 2558Kanjana thong
 
Centrolene Network - January 2016
Centrolene Network - January 2016Centrolene Network - January 2016
Centrolene Network - January 2016Ulli Wrieden
 
Materiales para el aprendizaje de los cbc
Materiales para el aprendizaje de los cbcMateriales para el aprendizaje de los cbc
Materiales para el aprendizaje de los cbcnoeordeig
 
Algorithm to correct Varus Knee in a TKR
Algorithm to correct Varus Knee in a TKRAlgorithm to correct Varus Knee in a TKR
Algorithm to correct Varus Knee in a TKRVaibhav Bagaria
 
Lista geometria polaridade TERCEIRÃO SARTRE
Lista geometria polaridade TERCEIRÃO SARTRE Lista geometria polaridade TERCEIRÃO SARTRE
Lista geometria polaridade TERCEIRÃO SARTRE Rodrigo Sampaio
 
Módulo lectura critica 2015 1
Módulo lectura critica 2015 1Módulo lectura critica 2015 1
Módulo lectura critica 2015 1ENSUMOR
 
муниципальное задание 2016
муниципальное задание 2016муниципальное задание 2016
муниципальное задание 2016SvetaF
 

Destacado (18)

Componentes de la educaciÓn geogrÁfica
Componentes de la educaciÓn geogrÁfica Componentes de la educaciÓn geogrÁfica
Componentes de la educaciÓn geogrÁfica
 
The Next Sixty Days
The Next Sixty DaysThe Next Sixty Days
The Next Sixty Days
 
Don't Quit! Improving Your District's Community Engagement & Communication is...
Don't Quit! Improving Your District's Community Engagement & Communication is...Don't Quit! Improving Your District's Community Engagement & Communication is...
Don't Quit! Improving Your District's Community Engagement & Communication is...
 
สรุปผลการดำเนินการจัดซื้อจัดจ้างในรอบเดือน ตุลาคม - ธันวาคม 2558
สรุปผลการดำเนินการจัดซื้อจัดจ้างในรอบเดือน ตุลาคม - ธันวาคม 2558สรุปผลการดำเนินการจัดซื้อจัดจ้างในรอบเดือน ตุลาคม - ธันวาคม 2558
สรุปผลการดำเนินการจัดซื้อจัดจ้างในรอบเดือน ตุลาคม - ธันวาคม 2558
 
Centrolene Network - January 2016
Centrolene Network - January 2016Centrolene Network - January 2016
Centrolene Network - January 2016
 
Nevula2
Nevula2Nevula2
Nevula2
 
Ing Dipl
Ing DiplIng Dipl
Ing Dipl
 
Materiales para el aprendizaje de los cbc
Materiales para el aprendizaje de los cbcMateriales para el aprendizaje de los cbc
Materiales para el aprendizaje de los cbc
 
egregora-e-seu-modus-operandis
 egregora-e-seu-modus-operandis egregora-e-seu-modus-operandis
egregora-e-seu-modus-operandis
 
Algorithm to correct Varus Knee in a TKR
Algorithm to correct Varus Knee in a TKRAlgorithm to correct Varus Knee in a TKR
Algorithm to correct Varus Knee in a TKR
 
Lista geometria polaridade TERCEIRÃO SARTRE
Lista geometria polaridade TERCEIRÃO SARTRE Lista geometria polaridade TERCEIRÃO SARTRE
Lista geometria polaridade TERCEIRÃO SARTRE
 
Módulo lectura critica 2015 1
Módulo lectura critica 2015 1Módulo lectura critica 2015 1
Módulo lectura critica 2015 1
 
Jsp Introduction Tutorial
Jsp Introduction TutorialJsp Introduction Tutorial
Jsp Introduction Tutorial
 
Ideologías totalitarias
Ideologías totalitariasIdeologías totalitarias
Ideologías totalitarias
 
Java project-presentation
Java project-presentationJava project-presentation
Java project-presentation
 
Sociedad de masas años ´20
Sociedad de masas años ´20Sociedad de masas años ´20
Sociedad de masas años ´20
 
Unix Dateisysteme
Unix DateisystemeUnix Dateisysteme
Unix Dateisysteme
 
муниципальное задание 2016
муниципальное задание 2016муниципальное задание 2016
муниципальное задание 2016
 

Similar a Objetos implícitos

Similar a Objetos implícitos (20)

Objetos Implicitos de JSP
Objetos Implicitos de JSPObjetos Implicitos de JSP
Objetos Implicitos de JSP
 
JSPobjetosimplicitos
JSPobjetosimplicitosJSPobjetosimplicitos
JSPobjetosimplicitos
 
Objetos implícitos
Objetos implícitosObjetos implícitos
Objetos implícitos
 
Seminario jquery, html5 y wicket
Seminario jquery, html5 y wicketSeminario jquery, html5 y wicket
Seminario jquery, html5 y wicket
 
Objetos implicitos
Objetos implicitosObjetos implicitos
Objetos implicitos
 
Introducción a Django
Introducción a DjangoIntroducción a Django
Introducción a Django
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Guiajquery
GuiajqueryGuiajquery
Guiajquery
 
Objetos implicitos de jsp
Objetos implicitos de jspObjetos implicitos de jsp
Objetos implicitos de jsp
 
Introducción a prototype javascript
Introducción a prototype javascriptIntroducción a prototype javascript
Introducción a prototype javascript
 
Aplicaciones pagina web
Aplicaciones pagina webAplicaciones pagina web
Aplicaciones pagina web
 
Introducción al desarrollo Web: Frontend con Angular 6
Introducción al desarrollo Web: Frontend con Angular 6Introducción al desarrollo Web: Frontend con Angular 6
Introducción al desarrollo Web: Frontend con Angular 6
 
(Muy breve) Introduccion a jQuery
(Muy breve) Introduccion a jQuery(Muy breve) Introduccion a jQuery
(Muy breve) Introduccion a jQuery
 
JSP
JSPJSP
JSP
 
Unidad 3 AJAX
Unidad 3 AJAX Unidad 3 AJAX
Unidad 3 AJAX
 
Unidad3ajax
Unidad3ajaxUnidad3ajax
Unidad3ajax
 
T10_Ejercicios_Solucion.pdf
T10_Ejercicios_Solucion.pdfT10_Ejercicios_Solucion.pdf
T10_Ejercicios_Solucion.pdf
 
Objetos implicitos en JSP
Objetos implicitos en JSPObjetos implicitos en JSP
Objetos implicitos en JSP
 
JSP objetos implicitos
JSP objetos implicitosJSP objetos implicitos
JSP objetos implicitos
 

Último

Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...Carlos Muñoz
 
RETO MES DE ABRIL .............................docx
RETO MES DE ABRIL .............................docxRETO MES DE ABRIL .............................docx
RETO MES DE ABRIL .............................docxAna Fernandez
 
MAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grandeMAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grandeMarjorie Burga
 
FORTI-MAYO 2024.pdf.CIENCIA,EDUCACION,CULTURA
FORTI-MAYO 2024.pdf.CIENCIA,EDUCACION,CULTURAFORTI-MAYO 2024.pdf.CIENCIA,EDUCACION,CULTURA
FORTI-MAYO 2024.pdf.CIENCIA,EDUCACION,CULTURAEl Fortí
 
Registro Auxiliar - Primaria 2024 (1).pptx
Registro Auxiliar - Primaria  2024 (1).pptxRegistro Auxiliar - Primaria  2024 (1).pptx
Registro Auxiliar - Primaria 2024 (1).pptxFelicitasAsuncionDia
 
Planificacion Anual 2do Grado Educacion Primaria 2024 Ccesa007.pdf
Planificacion Anual 2do Grado Educacion Primaria   2024   Ccesa007.pdfPlanificacion Anual 2do Grado Educacion Primaria   2024   Ccesa007.pdf
Planificacion Anual 2do Grado Educacion Primaria 2024 Ccesa007.pdfDemetrio Ccesa Rayme
 
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptxSINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptxlclcarmen
 
30-de-abril-plebiscito-1902_240420_104511.pdf
30-de-abril-plebiscito-1902_240420_104511.pdf30-de-abril-plebiscito-1902_240420_104511.pdf
30-de-abril-plebiscito-1902_240420_104511.pdfgimenanahuel
 
TIPOLOGÍA TEXTUAL- EXPOSICIÓN Y ARGUMENTACIÓN.pptx
TIPOLOGÍA TEXTUAL- EXPOSICIÓN Y ARGUMENTACIÓN.pptxTIPOLOGÍA TEXTUAL- EXPOSICIÓN Y ARGUMENTACIÓN.pptx
TIPOLOGÍA TEXTUAL- EXPOSICIÓN Y ARGUMENTACIÓN.pptxlclcarmen
 
Informatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos BásicosInformatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos BásicosCesarFernandez937857
 
La empresa sostenible: Principales Características, Barreras para su Avance y...
La empresa sostenible: Principales Características, Barreras para su Avance y...La empresa sostenible: Principales Características, Barreras para su Avance y...
La empresa sostenible: Principales Características, Barreras para su Avance y...JonathanCovena1
 
Historia y técnica del collage en el arte
Historia y técnica del collage en el arteHistoria y técnica del collage en el arte
Historia y técnica del collage en el arteRaquel Martín Contreras
 
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOSTEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOSjlorentemartos
 
Manual - ABAS II completo 263 hojas .pdf
Manual - ABAS II completo 263 hojas .pdfManual - ABAS II completo 263 hojas .pdf
Manual - ABAS II completo 263 hojas .pdfMaryRotonda1
 
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptxACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptxzulyvero07
 
2024 - Expo Visibles - Visibilidad Lesbica.pdf
2024 - Expo Visibles - Visibilidad Lesbica.pdf2024 - Expo Visibles - Visibilidad Lesbica.pdf
2024 - Expo Visibles - Visibilidad Lesbica.pdfBaker Publishing Company
 
TECNOLOGÍA FARMACEUTICA OPERACIONES UNITARIAS.pptx
TECNOLOGÍA FARMACEUTICA OPERACIONES UNITARIAS.pptxTECNOLOGÍA FARMACEUTICA OPERACIONES UNITARIAS.pptx
TECNOLOGÍA FARMACEUTICA OPERACIONES UNITARIAS.pptxKarlaMassielMartinez
 
Lecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdadLecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdadAlejandrino Halire Ccahuana
 
Heinsohn Privacidad y Ciberseguridad para el sector educativo
Heinsohn Privacidad y Ciberseguridad para el sector educativoHeinsohn Privacidad y Ciberseguridad para el sector educativo
Heinsohn Privacidad y Ciberseguridad para el sector educativoFundación YOD YOD
 

Último (20)

Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
Plan Refuerzo Escolar 2024 para estudiantes con necesidades de Aprendizaje en...
 
RETO MES DE ABRIL .............................docx
RETO MES DE ABRIL .............................docxRETO MES DE ABRIL .............................docx
RETO MES DE ABRIL .............................docx
 
MAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grandeMAYO 1 PROYECTO día de la madre el amor más grande
MAYO 1 PROYECTO día de la madre el amor más grande
 
FORTI-MAYO 2024.pdf.CIENCIA,EDUCACION,CULTURA
FORTI-MAYO 2024.pdf.CIENCIA,EDUCACION,CULTURAFORTI-MAYO 2024.pdf.CIENCIA,EDUCACION,CULTURA
FORTI-MAYO 2024.pdf.CIENCIA,EDUCACION,CULTURA
 
Registro Auxiliar - Primaria 2024 (1).pptx
Registro Auxiliar - Primaria  2024 (1).pptxRegistro Auxiliar - Primaria  2024 (1).pptx
Registro Auxiliar - Primaria 2024 (1).pptx
 
Planificacion Anual 2do Grado Educacion Primaria 2024 Ccesa007.pdf
Planificacion Anual 2do Grado Educacion Primaria   2024   Ccesa007.pdfPlanificacion Anual 2do Grado Educacion Primaria   2024   Ccesa007.pdf
Planificacion Anual 2do Grado Educacion Primaria 2024 Ccesa007.pdf
 
Presentacion Metodología de Enseñanza Multigrado
Presentacion Metodología de Enseñanza MultigradoPresentacion Metodología de Enseñanza Multigrado
Presentacion Metodología de Enseñanza Multigrado
 
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptxSINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
SINTAXIS DE LA ORACIÓN SIMPLE 2023-2024.pptx
 
30-de-abril-plebiscito-1902_240420_104511.pdf
30-de-abril-plebiscito-1902_240420_104511.pdf30-de-abril-plebiscito-1902_240420_104511.pdf
30-de-abril-plebiscito-1902_240420_104511.pdf
 
TIPOLOGÍA TEXTUAL- EXPOSICIÓN Y ARGUMENTACIÓN.pptx
TIPOLOGÍA TEXTUAL- EXPOSICIÓN Y ARGUMENTACIÓN.pptxTIPOLOGÍA TEXTUAL- EXPOSICIÓN Y ARGUMENTACIÓN.pptx
TIPOLOGÍA TEXTUAL- EXPOSICIÓN Y ARGUMENTACIÓN.pptx
 
Informatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos BásicosInformatica Generalidades - Conceptos Básicos
Informatica Generalidades - Conceptos Básicos
 
La empresa sostenible: Principales Características, Barreras para su Avance y...
La empresa sostenible: Principales Características, Barreras para su Avance y...La empresa sostenible: Principales Características, Barreras para su Avance y...
La empresa sostenible: Principales Características, Barreras para su Avance y...
 
Historia y técnica del collage en el arte
Historia y técnica del collage en el arteHistoria y técnica del collage en el arte
Historia y técnica del collage en el arte
 
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOSTEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
TEMA 13 ESPAÑA EN DEMOCRACIA:DISTINTOS GOBIERNOS
 
Manual - ABAS II completo 263 hojas .pdf
Manual - ABAS II completo 263 hojas .pdfManual - ABAS II completo 263 hojas .pdf
Manual - ABAS II completo 263 hojas .pdf
 
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptxACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
ACUERDO MINISTERIAL 078-ORGANISMOS ESCOLARES..pptx
 
2024 - Expo Visibles - Visibilidad Lesbica.pdf
2024 - Expo Visibles - Visibilidad Lesbica.pdf2024 - Expo Visibles - Visibilidad Lesbica.pdf
2024 - Expo Visibles - Visibilidad Lesbica.pdf
 
TECNOLOGÍA FARMACEUTICA OPERACIONES UNITARIAS.pptx
TECNOLOGÍA FARMACEUTICA OPERACIONES UNITARIAS.pptxTECNOLOGÍA FARMACEUTICA OPERACIONES UNITARIAS.pptx
TECNOLOGÍA FARMACEUTICA OPERACIONES UNITARIAS.pptx
 
Lecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdadLecciones 04 Esc. Sabática. Defendamos la verdad
Lecciones 04 Esc. Sabática. Defendamos la verdad
 
Heinsohn Privacidad y Ciberseguridad para el sector educativo
Heinsohn Privacidad y Ciberseguridad para el sector educativoHeinsohn Privacidad y Ciberseguridad para el sector educativo
Heinsohn Privacidad y Ciberseguridad para el sector educativo
 

Objetos implícitos

  • 2. SESSIONS ● Es un objeto de la clase HttpSession. Nos permite acceder a la sesión asociada a la petición. A través de este objeto podemos, entre otras cosas, guardar objetos que serán accesibles desde cualquier JSPde la sesión o invalidarla .Para guardar y recuperar información usaremos:Objectsession.getAttribute("clave");void session.setAttribute("clave", Object objeto);Y para invalidar la sesión: void session.invalidate();
  • 3. EJEMPLO <%@ page import="java.io.*,java.util.*" %> <% // Get session creation time. Date createTime = new Date(session.getCreationTime()); // Get last access time of this web page. Date lastAccessTime = new Date(session.getLastAccessedTime()); String title = "Welcome Back to my website"; Integer visitCount = new Integer(0); String visitCountKey = new String("visitCount"); String userIDKey = new String("userID"); String userID = new String("ABCD"); // Check if this is new comer on your web page. if (session.isNew()){ title = "Welcome to my website"; session.setAttribute(visitCountKey, visitCount); } visitCount = (Integer)session.getAttribute(visitCountKey); visitCount = visitCount + 1; userID = (String)session.getAttribute(userIDKey ); session.setAttribute(visitCountKey, visitCount); %> <html> <head> <title>Session Tracking</title>
  • 4. ● </head> ● <body> ● <center> ● <h1>Session Tracking</h1> ● </center> ● <table border="1" align="center"> ● <tr bgcolor="#949494"> ● <th>Session info</th> ● <th>Value</th> ● </tr> ● <tr> ● <td>id</td> ● <td><% out.print( session.getId()); %></td> ● </tr> ● <tr> ● <td>Creation Time</td> ● <td><% out.print(createTime); %></td> ● </tr> ● <tr> ● <td>Time of Last Access</td> ● <td><% out.print(lastAccessTime); %></td> ● </tr> ● <tr> ● <td>User ID</td> ● <td><% out.print(userID); %></td> ● </tr> ● <tr> ● <td>Number of visits</td> ● <td><% out.print(visitCount); %></td> ● </tr> ● </table> ● </body> ● </html>
  • 5. APPLICATION ● Es un objeto de la clase ServletContext .Este objeto es común para toda la aplicación web y,entre otras cosas, nos permite almacenar información que será accesible desde todas las páginas de la aplicación web, independientemente de la sesión .Para guardar y recuperar valores: *Object application.getAttribute("clave"); *void application.setAttribute("clave", Object objeto);
  • 6. EJEMPLO ●<%@ page import="java.io.*,java.util.*" %> ●<html> ●<head> ●<title>Application Implicit Object Example</title> ●</head> ●<body> ●<% ● //Comment: This would return null for the first time ● Integer counter= (Integer)application.getAttribute("numberOfVisits");
  • 7. ● if( counter ==null || counter == 0 ){ ● //Comment: For the very first Visitor ● counter = 1; ● }else{ ● //Comment: For Others ● counter = counter+ 1; ● } ● application.setAttribute("numberOfVisits", counter); ● %> ● <h3>Total number of hits to this Page is: <%= counter%></h3> ● </body> ● </html>
  • 8. CONFIG ● Es un objeto de la clase ServeletConfig. Permite acceder a parámetros de inicialización del Servlet y a su contexto.
  • 9. EJEMPLO ●<html> ●<head> <title> Config Implicit Object</title> ●</head> ●<body> ●<% ●String sname=config.getServletName(); ●out.print("Servlet Name is: "+sname); ●%> ●</body> ●</html>
  • 10. PAGECONTEXT ● Es un objeto de la clase PageContext. Entre otras cosas, nos permite almacenar información localmente a la página .Para guardar y recuperar valores: Object pageContext.getAttribute("clave");void pageContext.setAttribute("clave", Object objeto);
  • 11. EJEMPLO ● También podemos usar PageContext para almacenar y recuperar información en sesión y en aplicación: ● Almacenar en contexto de pagina : PageContext.setAttribute("clave", obj, PageContext. PAGE _SCOPE); ● PageContext.setAttribute("clave", obj); ● Almacenar en contexto de sesión : PageContext.setAttribute("clave",obj, Page Context . SESSION_SCOPE); ● session.setAttribute("clave", objeto); ● Almacenar en contexto de aplicación:PageContext.setAttribute("clave",obj,PageContext.A PPLICATION_SCOPE); ● application.setAttribute("clave",objeto);
  • 12. PAGE ● Es un sinónimo de this, no tiene utilidad en el estado actual de la especificación.