public class pr1_jsp extends H t t p J s p B a s e {
private static java . util . Vector _ j s p x _ i n c l u d e s ;
public java . util . List g e t I n c l u d e s () {
return _ j s p x _ i n c l u d e s ;
}
public void _ j s p S e r v i c e ( H t t p S e r v l e t R e q u e s t request , H t t p S e r v l e t R e s p o n s e r e s p o n s e )
throws java . io . IOException , S e r v l e t E x c e p t i o n {
/* C u e r p o del m é t o d o que que r e a l i z a el s e r v i c i o */
}
}
Luis Fernando Llana Díaz
Departamento de Sistemas Informáticos y ComputaciónUniversidad Complutense de Madrid
JSP: Java Server Pages
Traducción a servlet II
public void _ j s p S e r v i c e ( H t t p S e r v l e t R e q u e s t request , H t t p S e r v l e t R e s p o n s e r e s p o n s e )
throws java . io . IOException , S e r v l e t E x c e p t i o n {
J s p F a c t o r y _ j s p x F a c t o r y = null ;
javax . servlet . jsp . P a g e C o n t e x t p a g e C o n t e x t = null ;
H t t p S e s s i o n session = null ;
S e r v l e t C o n t e x t a p p l i c a t i o n = null ;
S e r v l e t C o n f i g config = null ;
J s p W r i t e r out = null ;
Object page = this ;
J s p W r i t e r _ j s p x _ o u t = null ;
try {
_ j s p x F a c t o r y = J s p F a c t o r y . g e t D e f a u l t F a c t o r y ();
r e s p o n s e . s e t C o n t e n t T y p e ( " text / html ; charset = ISO -8859 -1 " );
p a g e C o n t e x t = _ j s p x F a c t o r y . g e t P a g e C o n t e x t ( this , request , response , null , true , 8192 , true );
a p p l i c a t i o n = p a g e C o n t e x t . g e t S e r v l e t C o n t e x t ();
config = p a g e C o n t e x t . g e t S e r v l e t C o n f i g ();
session = p a g e C o n t e x t . g e t S e s s i o n ();
out = p a g e C o n t e x t . getOut ();
_ j s p x _ o u t = out ;
/* T r a d u c c i ó n de la p á g i n a */
} catch ( T h r o w a b l e t ) {
out = _ j s p x _ o u t ;
if ( out != null && out . g e t B u f f e r S i z e () != 0) out . c l e a r B u f f e r ();
if ( p a g e C o n t e x t != null ) p a g e C o n t e x t . h a n d l e P a g e E x c e p t i o n ( t );
} finally {
Luis Fernando Llana Díaz
Departamento de Sistemas Informáticos y ComputaciónUniversidad Complutense de Madrid
JSP: Java Server Pages
Traducción a servlet III
if ( _ j s p x F a c t o r y != null ) _ j s p x F a c t o r y . r e l e a s e P a g e C o n t e x t ( p a g e C o n t e x t );
}
Traducción de la página
out . write ( " <! - - $Id : t r a n s p a r e n c i a s . tex , v 1.2 2008 -04 -26 1 4 : 5 3 : 0 7 luis Exp $ - - >\ n " );
out . write ( " < html >\ n " );
out . write ( " < body >\ n " );
String nombre = request . g e t P a r a m e t e r ( " nombre " );
if ( nombre == null ) {
nombre = " Mundo " ;
}
out . write ( " \ n " );
out . write ( " <p > Hola " );
out . print ( nombre );
out . write ( " </p >\ n " );
out . write ( " </ body >\ n " );
out . write ( " </ html > " );
Luis Fernando Llana Díaz
Departamento de Sistemas Informáticos y ComputaciónUniversidad Complutense de Madrid
JSP: Java Server Pages
< html >
<! - - $Id : t r a n s p a r e n c i a s . tex , v 1.2 2008 -04 -26 1 4 : 5 3 : 0 7 luis Exp $ -->
< body >
< %
int numero ;
try {
numero = Integer . p a r s e I n t ( request . g e t P a r a m e t e r ( " numero " ));
} catch ( N u m b e r F o r m a t E x c e p t i o n e ) {
numero =1;
}
%>
< table >
< %
for ( int i = 1; i <= 10 ; i ++) {
%>
<tr > < td > < %= i %></ td > < td > < %= numero %></ td > < td > < %= i * numero %></ td > </ tr >
< %
}
%>
</ table >
Luis Fernando Llana Díaz
Departamento de Sistemas Informáticos y ComputaciónUniversidad Complutense de Madrid
JSP: Java Server Pages
< table >
< %
for ( int i = 1; i <= 10; i ++) {
out . print ( " <tr > " );
out . print ( " <td > " + i + " </ td > " );
out . print ( " <td > " + numero + " </ td > " );
out . print ( " <td > " +( i * numero )+ " </ td > " );
out . println ( " </ tr > " );
}
%>
</ table >
</ body >
</ html >
Luis Fernando Llana Díaz
Departamento de Sistemas Informáticos y ComputaciónUniversidad Complutense de Madrid
JSP: Java Server Pages
Directivas: < %@ directiva atributos %> I
< html >
< body >
< %@ page import = " java . util . Date " %>
< %@ page import = " java . text . D a t e F o r m a t " %>
< %@ page import = " java . text . S i m p l e D a t e F o r m a t " %>
< %
Date date = new Date ();
D a t e F o r m a t df = new S i m p l e D a t e F o r m a t ( " dd ’ de ’ MMMM ’ de ’ yyyy " );
%>
<p > Hoy es < %=df . format ( date ) %> </ p >
</ body >
</ html >
< %@ include file = " jsp / c a b e c e r a . jsp " %>
< h1 > C a p í t u l o 1 </ h1 >
< %@ include file = " html / c a p i t u l o 1 . html " %>
< h1 > C a p í t u l o 2 </ h1 >
< %@ include file = " html / c a p i t u l o 2 . html " %>
< h1 > C a p í t u l o 3 </ h1 >
< %@ include file = " html / c a p i t u l o 3 . html " %>
< h1 > C a p í t u l o 4 </ h1 >
< %@ include file = " html / c a p i t u l o 4 . html " %>
< %@ include file = " html / pie . html " %>
Luis Fernando Llana Díaz
Departamento de Sistemas Informáticos y ComputaciónUniversidad Complutense de Madrid
JSP: Java Server Pages
Directivas: < %@ directiva atributos %> II
Luis Fernando Llana Díaz
Departamento de Sistemas Informáticos y ComputaciónUniversidad Complutense de Madrid
JSP: Java Server Pages
Habichuelas Java: JavaBeans
< body >
< jsp : useBean id = " valor " scope = " request " class = " valores . Valor " / >
< jsp : s e t P r o p e r t y name = " valor " p r o p e r t y = " * " / >
< %
if ( valor . g e t N o m b r e ()== null || valor . g e t I b e x _ i d ()== null ||
valor . getUrl ()== null || valor . getTipo ()==0 ) {
String nombre = valor . g e t N o m b r e ()== null ? " " : valor . g e t N o m b r e ();
String ibex_id = valor . g e t I b e x _ i d ()== null ? " " : valor . g e t I b e x _ i d ();
String url = valor . getUrl ()== null ? " " : valor . getUrl ();
int tipo = valor . getTipo ( ) = = 0 ? 0 : valor . getTipo ();
%>
< form action = " pr5 . jsp " method = " get " >
<p >
< label > Nombre : </ label > < input name = " nombre " value = " < %= nombre %>" > < br >
< label > ibex_id : </ label > < input name = " ibex_id " value = " < %= ibex_id %>" > < br >
< label > URL : </ label > < input name = " url " value = " < %= url %>" > < br >
< label > Tipo </ label >
< select name = " tipo " >
< option value = " < %= Valor . A C C I O N E S %>" > A c c i o n e s </ option >
< option value = " < %= Valor . FONDOS %>" > Fondos </ opcion >
</ select >
< button type = " submit " > Enviar </ button >
} else { %>
</ p >
</ form >
< %
< jsp : g e t P r o p e r t y name = " valor " p r o p e r t y = " datos " / >
< %
</ body >
} %>
Luis Fernando Llana Díaz
Departamento de Sistemas Informáticos y ComputaciónUniversidad Complutense de Madrid
JSP: Java Server Pages
Etiquetas personalizadas I
< body >
< %
String nombre = request . g e t P a r a m e t e r ( " nombre " );
String ibex_id = request . g e t P a r a m e t e r ( " ibex_id " );
String url = request . g e t P a r a m e t e r ( " url " );
String strTipo = request . g e t P a r a m e t e r ( " tipo " );
int tipo = strTipo == null ? 0: Integer . p a r s e I n t ( strTipo );
if ( nombre == null || url == null || tipo ==0) {
%>
< form action = " pr6 . jsp " method = " get " >
<p >
< label > Nombre : </ label > < input name = " nombre " value = " < %= nombre == null ? " " : nombre %>" > < br >
< label > Ibex ID : </ label > < input name = " ibex_id " value = " < %= ibex_id == null ? " " : ibex_id %>" > < br >
< label > url : </ label > < input name = " url " value = " < %= url == null ? " " : url %>" > < br >
< label > Tipo : </ label >
< select name = " tipo " >
< option value = " < %= Valor . A C C I O N E S %>" > A c c i o n e s </ option >
< option value = " < %= Valor . FONDOS %>" > Fondos </ opcion >
Comentarios de: JSP: Java Server Pages (0)
No hay comentarios