1. Trang chủ
  2. » Công Nghệ Thông Tin

Head First Servlets and JSP phần 7 pptx

74 370 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 74
Dung lượng 2,34 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Use the optional Òv arÓ attribute when you want access to this value l ater.... Note: the exception implicit object is available ONLY to error pages with an explicitly-deÞ ned page dire

Trang 1

Unlike the other t wo includes, the <c:import> url can be f

rom outside the web Container!

WKH FLPSRUW! WDJ

Trang 2

Òhorse.htmlÓ and Òhorse.gifÓ are both on Server B, a completely different web server from the one with the JSP

(DonÕt forget: as with other include mechanisms, the thing you import should be an HTML fragment and NOT a complete page with opening and closing <html><body> tags.)

Trang 3

as a new request parameter.

WKH FLPSRUW! WDJ

Trang 4

This page doesnÕt change a t all It doesnÕt care HOW the parameter got there, as long as itÕs ther e.

No slash, because NOW the tag has a body

Trang 7

FVHWYDU ´ODVW´YDOXH ´+LGGHQ&XUVRU´!

FVHWYDU ´¿UVW´YDOXH ´&URXFKLQJ3L[HOV´!

FXUOYDOXH ´LQSXW&RPPHQWVMVS"¿UVW ^¿UVW` ODVW ^ODVW`´YDU ´LQSXW85/´!

7KH85/XVLQJSDUDPVLV^LQSXW85/`EU!

2EMEMBER

KWWSORFDOKRVWWHVWVULVN\MVS

7KH85/XVLQJSDUDPVLVP\$SSLQSXW&RPPHQWV

MVS"ÀUVW &URXFKLQJ3L[HOV ODVW +LGGHQ&XUVRU

Uh-oh youÕre not supp osed to have spaces in a URL!

Yikes! Query string parameter s have

to be encoded spaces, f or example, must be replaced with a plus Ò+Ó sign.

Use the optional Òv arÓ attribute when you want access to this value l ater

8VLQJFSDUDP!LQWKHERG\RIFXUO!

4HIS

FXUOYDOXH ´LQSXW&RPPHQWVMVS´YDU ´LQSXW85/´!

 FSDUDPQDPH ´¿UVW1DPH´YDOXH ´^¿UVW`´!

FSDUDPQDPH ´ODVW1DPH´YDOXH ´^ODVW`´!

FXUO!

no slash

.OW

P\$SSLQSXW&RPPHQWVMVS"¿UVW1DPH &URXFKLQJ3L[HOV ODVW1DPH +LGGHQ&XUVRU

Now weÕre safe, because <c:param>

takes care of the encoding!

WKH F85/! WDJ

Trang 9

ConÞ rms for the Container, ÒY es, this IS

an ofÞ cially-designated error page.Ó

Tells the Container, ÒIf something goes wrong here, forward the request to errorPage.jspÓ.

The REQUEST was for ÒbadPage.jspÓ, but that page threw an exception, so the RESPONSE came from ÒerrorPage.jspÓ.

HUURU SDJHV

Trang 10

\RXDUHKHUH 

;PMLWM[V¼\SVW_IJW]\\PM$MZZWZXIOM&,,\IO

9OUCAN(440

4HEDEFAULT

Trang 11

The <location> MUST be rel ative to the web-app root/contex

t, which means it MUST start with a sl ash (This is true regardless of w

hether the error page is based on <error-code> or <exc eption-type>.)

HUURUSDJHV LQWKH''

Trang 12

Note: the exception implicit object is available ONLY to error pages with an explicitly-deÞ ned page directive:

<%@ page isErrorPage=ÓtrueÓ %>

In other words, conÞ guring an error page in the DD is not enough to make the Container give that page the implicit exception object!

Trang 13

ANDANDMIGHT

AND

TAGCAUGHTEITHER OF

#WDJOLESUH¿[ ´F´XUL ´KWWSMDYDVXQFRPMVSMVWOFRUH´!

If this prints out, then we KNOW

we made it past the exception (which in this example, means we successfully caught the exception).

Trang 14

This creates a new page-scop ed attribute named ÒmyExc eptionÓ, and assigns the exception object t o it.

Now thereÕs an attribute myException, and since itÕs a Throwable, it has a

has a getMessage() method).

Trang 16

We didnÕt cover this one it lets

you iterate over tokens where YOU

give it the delimiter Works a lot

like StringTokenizer We also didnÕt

cover <c:redirect> and <c:out>, but

that gives you a wonderful excuse

to get the JSTL docs.

Trang 17

4,$ 4,$

)TSTHENAMETHE

UHDGLQJWKH 7/'

Trang 18

This is the v ersion of the XML schema tha

t you use for JSP 2.0 DonÕt memor

ize it

just copy it int o your <taglib> element.

MANDATORY (the tag, not the v

alue)Ñ the develop er puts it in to decl are the version of the tag library.

REQUIRED! This is wha t you use inside the tag (example: <my:advic e>). REQUIRED ! This is how the

Container knows wha

t to call when someone uses the tag in a JSP.

If your tag has attributes, then one <attribute>

element per tag attribute is required.

The unique name we use

in the taglib directive!

REQUIRED! This says that the tag must NOT have anything in the body.

This says you MUST put a ÒuserÓ attribute in the tag.

This says the ÒuserÓ a ttribute can be a

r un t ime expr ession value (i.e

doesnÕt have to be a Str ing literal).

Optional, but a r eally good idea

MANDATORY; mainly for tools to use

Trang 19

in the TLD is set to ÒtrueÓ for the user attribute

(Assume the ÒuserNameÓ attribute already exists.)

7KH7/'HOHPHQWVIRUWKHDGYLFHWDJ

This is the same tag you saw

on the previous page, but without the annotations.

LQJV

UDQDGY

W\

HGSU

G

X

UHG!

YH

K

H¿

!

!HT



UD

ODVVFRLEDUH

UW

UHDGLQJWKH 7/'

Trang 20

The Container calls doT ag() when the JSP inv

okes the tag using the name decl ared in the TLD.

The Container calls this method t

o set the value from the tag attribute It uses Jav

aBean property naming conventions to Þ gure out tha

t a ÒuserÓ attribute should be sent to the setUser() method.

Our own interna l method.

Trang 21

If thereÕs no <rtexprv alue>, the default value is f alse.

Trang 22

It has to be an expression, not just a scriplet

So it must have the Ò=Ó sign in there and no semicolon on the end.

Trang 23

<jsp:attribute> tags donÕt count as Òbody contentÓ.

The tag must N OT have a body.

The tag must N OT have scripting elements (scr

iptlets, scripting expressions, and decl arations), but i

t CAN have template text and EL and cus

tom and standard actions.

The tag body is treated as plain text, so the EL is NOT evaluated and tags/actions are not triggered.

The tag body can have anything that can go inside a JSP.

WDJ ERGLHV

Trang 24

\RXDUHKHUH 

YRLGGR7DJ ^

WDJORJLF

`YRLGVHW8VHU 6WULQJXVHU

deploy and run a web app that uses the tag.

Trang 25

#WDJOLESUH¿[ ´F´XUL ´KWWSMDYDVXQFRPMVSMVWOFRUH´!

This LOOKS like a URL t o

a web resource, but i tÕs not

ItÕs just a name tha t happens

Trang 27

#WDJO XUL ´:

Trang 29

 FKDSWHU

YRLGGR7DJ ^

WDJORJLF

`YRLGVHW 6WULQJ[

Trang 30

FVHWYDU ´XVHU/HYHO´VFRSH ´VHVVLRQ´ ´IRR´!

6KDUSHQ \RXU SHQFLO

of the tag instead of as an a ttribute.

The <c:otherwise> tag is optiona l.

Trang 31

 FKDSWHU

YRLGGR7DJ ^

WDJORJLF

`YRLGVHWUser 6WULQJXVHU

Trang 32

!SSUMINGWHICH

Trang 33

 FKDSWHU

!VALUEASSOCIATED

VWUHHW ... class="text_page_counter">Trang 71

6LPSOH7DJ

7DJLQWHUIDFH

LQWGR(QG7DJ 7DJJHW3DUHQW LQWGR6WDUW7DJ YRLGVHW3DJH&RQWH[W 3DJH&RQWH[W...

MDYD[VHUYOHWMVSWDJH[W6LPSOH7DJ6XSSRUW

Trang 57< /span>

:HE&RQWDLQHU 6LPSOH7DJFODVV 7DJ+DQGOHU2EMHFW

Your tag handlerÕs...

iptlets, scripting expressions, and decl arations), but i

t CAN have template text and EL and cus

tom and standard actions.

The

Ngày đăng: 12/08/2014, 19:20

TỪ KHÓA LIÊN QUAN