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

Head First Servlets and JSP phần 8 potx

74 325 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

Tiêu đề When even JSTL is not enough...
Tác giả Bert Bates, Kathy Sierra, Bryan Basham
Trường học O'Reilly
Chuyên ngành Computer Programming
Thể loại sách chuyên khảo
Năm xuất bản 2004
Thành phố San Francisco
Định dạng
Số trang 74
Dung lượng 2,13 MB

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

Nội dung

This doAfterBody method was correct, but it runs only AFTER the body has already been processed once!. -Option C is invalid because an attribute in page scope would be found before check

Trang 1

But where do you loop over the body, if the body is evaluated in between the methods instead of IN a method like doT

ag()?

ItÕs easy to loop the body of a Simple tag;

you just keep calling invoke() on the body, from within doTag().

LWHUDWLQJZLWK&ODVVLFWDJV"

Trang 2

:HE&RQWDLQHU &ODVVLFWDJFODVV 7DJ+DQGOHU2EMHFW

These happen the Þ rst time the tag is inv oked, but the Container may (dep ending on the circumstances) r euse the Classic tag object after this.

This gives the handler a reference to a PageContext.

If the tag is invoked with attributes, the JavaBean-style setter for each attribute is called (just as with SimpleTag handlers).

A nested tag can communica te with the other tags in which i ts nested.

doAfterBody() lets you do things AFTER the body runs, and unlike the other methods it can be inv oked more than once.

The body is evaluated between the doStartTag() and doEndTag() methods.

Trang 3

&ODVVLFWDJOLIHF\FOH

Trang 4

public int doStartTag() throws JspException {

public int doAfterBody() throws JspException {

public int doEndTag() throws JspException {

}

Trang 5

'HVLUHGUHVXOW-63WKDWLQYRNHVWKHWDJ

#WDJOLESUH¿[ ´PLQH´XUL ´.DWK\&ODVVLF7DJV´!

Trang 6

HYDOXDWHG

Trang 7

$PHOLH

ThereÕs an empty cell at the top!

You MUST add these t wo lines

to produce the corr ect response

This doAfterBody() method was correct, but it runs only AFTER the body has already been processed once! Without the two extra lines in doStartTag(), the body is proc essed once without there being a movie attribute, so you get the empty c

ell.

&ODVVLFWDJH[HUFLVHDQVZHUV

Trang 8

YOUHAS9ES 3IMPLE4AGCOURSEYOUDTAGYOUDDO3TART4AG

ITS

THE FOR DO3TART4AG

JUST

HANDLERS

#LASSICANDMEANSINSTANCENEWDO3TART4AG WORKSAVARIABLEINSTEAD

Trang 11

IURPGR6WDUW7DJ  LI\RXU7/'GHFODUHVDQHPSW\ERG\IRUWKHWDJHYHQ,)

Trang 13

SKIP_BODY EVAL_BODY_AGAIN

SKIP_PAGE EVAL_PAGE

SKIP_BODY EVAL_BODY_INCLUDE

Exactly once, and ONLY if doStartTag() returns EVAL_BODY_BUFFERED

Trang 14

LQWHUIDFH!!

7DJ

Trang 15

LQWHUIDFH!!

7DJ

YRLGGR7DJ -VS7DJJHW3DUHQW YRLGVHW-VS%RG\ -VS)UDJPHQW YRLGVHW-VS&RQWH[W -VS&RQWH[W YRLGVHW3DUHQW -VS7DJSDUHQW

Again, donÕt forget the cas t.

ItÕs exactly the same as

in a Classic tag handler.

PLQH2XWHU7DJ!

PLQH,QQHU7DJ!

PLQH2XWHU7DJ!

$QHVWHGWDJFDQDFFHVVLWVSDUHQW HQFORVLQJ WDJ

In this relationship, ÒOuterTagÓ

is the parent of ÒInnerTagÓ.

WKHJHW3DUHQW ...

.H\OLIHF\FOHPHWKRGVWKDW

< 28 PLJKWLPSOHPHQW

doEndTag() doAfterBody() (and for BodyTagÑ doInitBody() and setBodyContent())

+RZ\RXZULWHWRWKHUHVSRQVH... invalid because the jsp: body action can appear in EITHER a tag Þle or JSP.

-Option F is invalid because the taglib directive can appear in EITHER a tag Þle or JSP.

-...

-Option A is invalid because Simple tags have a getParent method.

(JSP v2.0 SimpleTagSupport API pg 2 -86 JSP v2.0 TagSupport API pg 2-64)

-Option B is invalid because

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

TỪ KHÓA LIÊN QUAN