Java Server Pages

Anuncio
JSP
Java Server Pages
JSP: Introducción
!
"
#
!
"
$%
&
'
JSP: Introducción
(
)!*%)
! &
& ! & *
'
+
!*
,
!
-
$
-
/12/
JSP: Introducción
3
)
4
$
.
&
&
5
+
!*
6
3
)
%
&
'
.
/01/
JSP: Introducción
Elementos JSP
+
!*
3
&
*
)
*
)
)
%
'
!
*
&
Sintaxis de JSP
JSP: Sintaxis
<%= expression %>;
64
&
6
&
7
<jsp:expression> expression </jsp:expression>
&
request, response,
out, session, application, config.pageContext
<% code %>;
6
8
&
6
&
7
<jsp:scriptlet> code </jsp:scriptlet>.
JSP: Sintaxis
<%! code %>
6
& .
8
&
!
$
&
- 8
6
&
7
<jsp:declaration> code </jsp:declaration>.
)
&
9
<%@ directive att="val" %>
8
:
&
<%@ directive
attribute1="value1“
attribute2="value2“
...
attributeN="valueN" %>
JSP: Sintaxis
<%-- comment --%>
(
&
!
4
- comment -->.
+
!*
.
<!-
<jsp:nombre-de-la-acción att=valor
att2=valor2 …/>
4 7
! &
+& ;
*
.
.
&
$
.
JSP: Expresiones
67*<6!#
=96!
!
<%= expresión %>
&
.
! & <
.
! & <
.
!
%
4 '
. * ,
%
&
+ ,
'
!
& :
&
Your hostname: <%= request.getRemoteHost() %>
JSP: Expresiones
6
&
&
7
4
4
<jsp:expression>
Expresión Java
</jsp:expression>
7
.
.
+
!*
Ejemplo. Expresión JSP
4
6
4
?
>
0
2
&
0 2
3
01@%
%''12
A
JSP: Scriptlets
!(<#
* 6!
<% código %>
8
&
&
4
6
.4 '
%
&
6
<html>
<% for ( int i = 0 ; i < 10 ; i ++ )
out.println(“<br>”+i);%>
</html>
JSP: Scriptlets
<% if (Math.random() < 0.5) { %>
Have a <B>nice</B> day!
<% } else { %>
Have a <B>lousy</B> day!
<% } %>
B
if (Math.random() < 0.5) {
out.write("Have a <B>nice</B> day!");}
else {
out.write("Have a <B>lousy</B> day!");}
JSP: Scriptlets
6
&
7
01 (
<jsp:scriptlet>
Código
</jsp:scriptlet>
!
/%>/
. /%\>/
12
JSP: Declaraciones
36( )<)(#
=96!
<%! codigo %>
& .
4
*
9
8
8
.&
!
<%! private int accessCount = 0; %>
Accesses to page since server reboot:
<%= ++accessCount %>
JSP: Declaraciones
(
6
.
&
<jsp:declaration>
Código
</jsp:declaration>
/%>/.
7
/%\>/
<%! Código %>
JSP: Directivas
)
&
9
<%@ directive attribute="value" %>
8
:
&
<%@ directive
attribute1="value1“
attribute2="value2“
...
attributeN="valueN" %>
JSP: Directivas
*)C6
import="package.class“
import="package.class1,...,package.classN/ 6
6
:
:
&
ContentType = "MIME-Type" contentType = "MIMEType; charset = Character-Set" 6
#6
6&
4"
&
Dresponse.setContentTypeE
isThreadSafe="true|false".
&
%
'
&
.
:
& .
$
&
&
SingleThreadModel
JSP: Directivas
session="true|false".
&
!
'
4
.
4
&
.-
&
+
!*
&
buffer="sizekb|none". 6
+ ,
6&
&
autoflush="true|false".
&
'
8
&
.
$ .
$
&
@/
/
%
%
4
'
&
&
F
GH
%
4
JSP: Directivas
extends="package.class". 6
&
&
3
4
.&
$
info="message". 3
8
! & #
errorPage="url". 6
$
isErrorPage="true|false". #
:
&
language="java". 6
$ *
.
8 &
:
$
+
!*
A
+
!* 6
&
Ejercicio
&
3
&
)F
$
&
01I
@/ & /
@/ &
J/
- @/ 4"
/
6
@/ KGGLMKN/ 12
+
(
9#
(=36
KN
JSP: Directivas
#
9(
36 *
+
!*
&
<%@ include file="url relativa" %>
$
&
;
4
.
&
+
!*.
JSP: Directivas
4 7
&
<jsp:directive.TipoDirectiva atributo=valor />
*
.
&
7
<%@ page import="java.util.*" %>
<jsp:directive.page import="java.util.*" />
JSP: Variables predefinidas
!"
%
<
#$6
! & <
.-
getParameter'.
%C6 .*=! . 6)3.
*
.
' 6
! & <
! & <
'.%
H .
.
.
* 6
&
JSP: Variables predefinidas
%& $6
! & <
(
.
.
&
&$
&
JSP: Variables predefinidas
%"#$ 6
&
8
*
*
,
!
:
&
,
+ ,
F
&
4
4
.
.
.
.
&
&
+
!*
.4
*
!
-
JSP: Variables predefinidas
'%&$6
!
.
&
:
4
&
&
.
+
!*
&
&
JSP: Variables predefinidas
('
#'%&$6 ! & (
4
getServletConfig().getContext().
%&)'*$6
! & (
* %&# +#$ +
!*
* (
4
&
&
+ ,
.
&8
&$
& "+
!*/
.
/
JSP: Variables predefinidas
* $6
this.-
-:
+&
Acciones JSP
+& O
JSP: Acciones
4 7
! &
*
+& ;
.
.
&
$
.
6
)
JSP: Acciones: include
'
'%&
$
4
<jsp:include page="relative URL" flush="true" />
)
&
&
! & .
.
JSP: Acciones: useBean
'
'%&
$
+& ;
+&
,
+
!*-
$
$
<jsp:useBean id="name" class="package.class" />
6
/
.- :
&
/ )
jsp:setProperty.
8
*
jsp:getProperty
-
JSP: Acciones: useBean
;
<jsp:useBean id="name" class="package.class" /
JSP: Acciones: useBean
id 3
&
!
&
class 3
scope
#
-
4
session, y application.
type 6
&
beanName
3
8
type -
.
;
beanName.-
&
page, request,
6
class
JSP: Acciones: setProperty
*
&
P
3
;
<jsp:useBean id="myName" ... />
...
<jsp:setProperty name="myName“
property="someProperty" ... />
!
-
JSP: Acciones: setProperty
3
;
<jsp:useBean id="myName“ ... >
...
<jsp:setProperty name="myName"
property="someProperty" ... />
</jsp:useBean>
!
-
JSP: Acciones: setProperty
Name
6
-
&
jsp:useBean
jsp:setProperty
Property 6
6
!
/J/
-
&
.
-
;
Value
8
6
&
&
8
param
&
.
&
= 9
value -
JSP: Acciones: setProperty
param
6
&
!
.
8
) .
&
.
<jsp:setProperty
!
8
name="orderBean“
property="numberOfItems"
param="numItems" />
.
Comunicación entre jsp
Posibles Ámbitos
&
&
Desarrollo de TAG-LIBs
*
*
3
3
*
A
3
.
4
%
'
Desarrollo de TAG-LIBs
3
%
3
8
'
&4
4
&
#
64
8
Q
!
; -
!
; -
64
#
8
Desarrollo de TAG-LIBs
Referencias
R
R
R
R
AAA &
AAA
&
""
"
+& ! &
*
=< -
"
S
P
6
T
Descargar