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

Head First Servlets and JSP phần 2 ppsx

74 467 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,6 MB

Nội dung

 FKDSWHU  3267 %HHUY6HOHFW%HHUGR +773 +RVWZZZZLFNHGO\VPDUWFRP 8VHU$JHQW0R]LOOD0DFLQWRVK8 33&0DF26;0DFK2HQ86UY *HFNR1HWVFDSH $FFHSWWH[W[PODSSOLFDWLRQ [PODSSOLFDWLRQ[KWPO[POWH[W KWPOT WH[WSODLQT YLGHR[ PQJLPDJHSQJLPDJHMSHJLPDJH JLIT T  'LDQHÀOOVRXWWKHIRUPDQGKLWVVXEPLW7KHEURZVHU JHQHUDWHVWKHUHTXHVW85/ %HHUY6HOHFW%HHUGR  The web app context root. The logical resource name. &RQWDLQHU &OLHQW 7KH&RQWDLQHUVHDUFKHVWKH'' DQGÀQGVDVHUYOHWPDSSLQJ! ZLWKDXUOSDWWHUQ!WKDW PDWFKHV 6HOHFW%HHUGRZKHUH WKHVODVKUHSUHVHQWVWKH FRQWH[WURRWRIWKHZHEDSSDQG 6HOHFW%HHUGRLVWKH ORJLFDO QDPH RIDUHVRXUFH  &RQWDLQHU  ZHEDSS! VHUYOHW! VHUYOHWQDPH! &K%HHU VHUYOHWQDPH! VHUYOHWFODVV! FRPH[DPSOHZHE%HHU6HOHFW VHUYOHWFODVV! VHUYOHW!  VHUYOHWPDSSLQJ! VHUYOHWQDPH! &K%HHU VHUYOHWQDPH! XUOSDWWHUQ! 6HOHFW%HHUGR XUOSDWWHUQ! VHUYOHWPDSSLQJ! ZHEDSS! &RQWDLQHU 7KH&RQWDLQHUVHHVWKDWWKHVHUYOHW QDPH!IRUWKLVXUOSDWWHUQ!LV´&K %HHUµ%XWWKDWLVQ·WWKHQDPHRIDQ DFWXDOVHUYOHWFODVVÀOH´&K%HHUµLV WKHQDPHRID VHUYOHW QRWDVHUYOHW FODVV  7RWKH&RQWDLQHUDVHUYOHWLVVRPHWKLQJ QDPHGLQWKH''XQGHUDVHUYOHW!WDJ 7KHQDPHRIWKHVHUYOHWLVVLPSO\WKH QDPHXVHGLQWKH''VRWKDWRWKHU SDUWVRIWKH''FDQPDSWRLW  5IXXQVO\PMTWOQKITVIUM\WI[MZ^TM\KTI[[NQTM In the HTML, the Ò/Beer-v1/Ó isnÕt part of the path. In the HTML, it just says: <form method=ÓPOSTÓ action=ÓSelectBeer.doÓ> But the browser prepends Ò/Beer-v1/Ó on to the request, because thatÕs where the client request is coming from. In other words, the ÒSelectBeer.doÓ in the HTML is relative to the URL of the page its on. In this case, relative to the root of the web app, Ò/Beer-v1Ó. The host server root. VHUYOHWPDSSLQJ Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited. KDQGVRQ09& \RXDUHKHUH   ZHEDSS! VHUYOHW! VHUYOHWQDPH! &K%HHU VHUYOHWQDPH! VHUYOHWFODVV! FRPH[DPSOHZHE%HHU6HOHFW VHUYOHWFODVV! VHUYOHW!  VHUYOHWPDSSLQJ! VHUYOHWQDPH! &K%HHU VHUYOHWQDPH! XUOSDWWHUQ! 6HOHFW%HHUGR XUOSDWWHUQ! VHUYOHWPDSSLQJ! ZHEDSS! H! E ! 7KH&RQWDLQHUORRNVLQVLGHWKH VHUYOHW!WDJVIRUVRPHWKLQJZLWK WKHVHUYOHWQDPH!´&K%HHUµ  7KH&RQWDLQHUXVHVWKH VHUYOHWFODVV!LQWKHVHUYOHW! WDJWRNQRZZKLFKVHUYOHWFODVV LVUHVSRQVLEOHIRUKDQGOLQJWKLV UHTXHVW,IWKHVHUYOHWKDV QRWEHHQLQLWLDOL]HGWKHFODVV LVORDGHGDQGWKHVHUYOHWLV LQLWLDOL]HG  7KH&RQWDLQHUVWDUWVDQHZWKUHDGWR KDQGOHWKHUHTXHVWDQGSDVVHVWKH UHTXHVWWRWKHWKUHDGWRWKHVHUYOHW·V VHUYLFHPHWKRG  VHUYOHW 7KH&RQWDLQHUVHQGVWKHUHVSRQVHWKURXJKWKH :HE6HUYHURIFRXUVHEDFNWRWKHFOLHQW  &OLHQW VHUYOHW UHTXHVW  +7732.  KWPO! KHDG!  KHDG! ERG\! LPJVUF ! ERG\! KWPO! UHVSRQVH  +7732.  KWPO! KHDG!  KHDG! ERG\! LPJVUF ! ERG\! KWPO! &RQWDLQHU &RQWDLQHU &RQWDLQHU &RQWDLQHU QDP U Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.  FKDSWHU <PMNQZ[\^MZ[QWVWN\PMKWV\ZWTTMZ[MZ^TM\ SDFNDJHFRPH[DPSOHZHE LPSRUWMDYD[VHUYOHW LPSRUWMDYD[VHUYOHWKWWS LPSRUWMDYDLR SXEOLFFODVV%HHU6HOHFWH[WHQGV+WWS6HUYOHW^ SXEOLFYRLGGR3RVW+WWS6HUYOHW5HTXHVWUHTXHVW   +WWS6HUYOHW5HVSRQVHUHVSRQVH  WKURZV,2([FHSWLRQ6HUYOHW([FHSWLRQ^  UHVSRQVHVHW&RQWHQW7\SH³WH[WKWPO´  3ULQW:ULWHURXW UHVSRQVHJHW:ULWHU RXWSULQWOQ³%HHU6HOHFWLRQ$GYLFHEU!´  6WULQJF UHTXHVWJHW3DUDPHWHU³FRORU´ RXWSULQWOQ³EU!*RWEHHUFRORU³F ` ` Be sure you match the development and deployment structures we created earlier. WeÕll use doPost to handle the HTTP request, because the HTML form says: method=POST This method comes from the ServletResponse interface. This method comes from the ServletRequest interface. Notice that the argument matches the value of the ÒnameÓ attribute in the HTMLÕs <select> tag. /URPLANISTOBUILDTHESERVLETINSTAGESTESTINGTHEVARIOUSCOMMUNICATION LINKSASWEGO)NTHEENDREMEMBERTHESERVLETWILLACCEPTAPARAMETERFROM THEREQUESTINVOKEAMETHODONTHEMODELSAVEINFORMATIONINAPLACETHE *30CANlNDANDFORWARDTHEREQUESTTOTHE*30"UTFORTHISlRSTVERSIONOUR GOALISJUSTTOMAKESURETHATTHE(4-,PAGECANPROPERLYINVOKETHESERVLET ANDTHATTHESERVLETISRECEIVINGTHE(4-,PARAMETERCORRECTLY HttpServlet extends GenericServlet, which implements the Servlet interface LQWHUIDFH!! MDYD[VHUYOHW6HUYOHW MDYD[VHUYOHW*HQHULF6HUYOHW MDYD[VHUYOHWKWWS+WWS6HUYOHW LQWHUIDFH!! MDYD[VHUYOHWKWWS+WWS6HUYOHW5HTXHVW LQWHUIDFH!! MDYD[VHUYOHW6HUYOHW5HTXHVW LQWHUIDFH!! MDYD[VHUYOHWKWWS+WWS6HUYOHW5HVSRQVH LQWHUIDFH!! MDYD[VHUYOHW6HUYOHW5HVSRQVH 6HUYOHWFRGH .H\$3,V WeÕre not giving back advice here, just displaying test information. VHUYOHWFRQWUROOHUYHUVLRQRQH Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited. KDQGVRQ09& \RXDUHKHUH  /KWEVEBUILTDEPLOYEDANDTESTEDOUR(4-,ANDWEVEBUILTANDDEPLOYEDOUR$$ WELLWEPUTTHEWEBXMLINTOTHEDEPLOYMENTENVIRONMENTBUTTECHNICALLYTHE$$ WONTBEDEPLOYEDUNTILWERESTART4OMCAT.OWITSTIMETOCOMPILETHElRSTVERSIONOF THESERVLETDEPLOYITANDTESTITVIATHE(4-,FORM.OWWELLRESTART4OMCATTOMAKE SURETHATIThSEESvTHEWEBXMLANDSERVLETCLASS +WUXQTQVOLMXTWaQVOIVL\M[\QVO\PMKWV\ZWTTMZ[MZ^TM\ &RPSLOLQJWKHVHUYOHW &RPSLOHWKHVHUYOHWZLWKWKHGÀDJWRSXWWKHFODVVLQWKHGHYHORSPHQWHQYLURQPHQW Adjust this to match your own directory path to your system! Everything after Òtomcat/Ó will be the same. Use the -d option to tell the compiler to put the .class Þ le into the classes directory within the correct package structure. Your .class Þ le will end up in /beerV1/classes/com/example/web/. 'HSOR\LQJWKHVHUYOHW 7RGHSOR\WKHVHUYOHWPDNHDFRS\RIWKHFODVV¿OHDQGPRYHLWWRWKH %HHUY:(%,1)FODVVHVFRPH[DPSOHZHEGLUHFWRU\LQWKHGHSOR\PHQWVWUXFWXUH 7HVWLQJWKHVHUYOHW 5HVWDUWWRPFDW /DXQFK\RXUEURZVHUDQGJRWR KWWSORFDOKRVW%HHUYIRUPKWPO 6HOHFWDEHHUFRORUDQGKLW³6XEPLW´ ,I\RXUVHUYOHWLVZRUNLQJ\RXVKRXOG VHHWKHVHUYOHW¶VUHVSRQVHLQ\RXUEURZVHU DVVRPHWKLQJOLNH  %HHU6HOHFWLRQ$GYLFH  *RWEHHUFRORUEURZQ FG0\3URMHFWVEHHU9 MDYDFFODVVSDWK8VHUVEHUW$SSOLFDWLRQVWRPFDWFRPPRQOLE VHUYOHWDSLMDUFODVVHVGFODVVHVVUFFRPH[DPSOHZHE%HHU6HOHFWMDYD )LOH(GLW:LQGRZ+HOS8SGDWH%UDLQ FGWRPFDW ELQVKXWGRZQVK ELQVWDUWXSVK )LOH(GLW:LQGRZ+HOS6ODVKGRW0H ZHEDSSV %HHUY :(%,1) ZHE FODVVHV FRP H[DPSOH      %HHU6HOHFWFODVV WRPFDW KWWSORFDOKRVW%HHUYIRUPKWPO Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.  FKDSWHU *]QTLQVOIVL\M[\QVO\PMUWLMTKTI[[  )N-6#THEMODELTENDSTOBETHEhBACKENDvOFTHEAPPLICATION)TSOFTENTHELEGACYSYSTEM THATSNOWBEINGEXPOSEDTOTHEWEB)NMOSTCASESITSJUSTPLAINOLD*AVACODEWITHNO KNOWLEDGEOFTHEFACTTHATITMIGHTBECALLEDBYSERVLETS4HEMODELSHOULDNTBETIEDDOWN TOBEINGUSEDBYONLYASINGLEWEBAPPSOITSHOULDBEINITSOWNUTILITYPACKAGES 7KHVSHFVIRUWKHPRGHO ,WVSDFNDJHVKRXOGEHFRPH[DPSOHPRGHO ,WVGLUHFWRU\VWUXFWXUHVKRXOGEH:(%,1)FODVVHVFRPPRGHO ,WH[SRVHVRQHPHWKRGJHW%UDQGVWKDWWDNHVDSUHIHUUHGEHHUFRORUDVD 6WULQJDQGUHWXUQVDQ$UUD\/LVWRIUHFRPPHQGHGEHHUEUDQGVDOVRDV6WULQJV %XLOGWKHWHVWFODVVIRUWKHPRGHO &UHDWHWKHWHVWFODVVIRUWKHPRGHO\HVEHIRUH\RXEXLOGWKHPRGHOLWVHOI<RX¶UHRQ \RXURZQKHUHZHGRQ¶WKDYHRQHLQWKLVWXWRULDO5HPHPEHUWKHPRGHOZLOOVWLOOEHLQWKH GHYHORSPHQWHQYLURQPHQWZKHQ\RX¿UVWWHVWLW²LW¶VMXVWOLNHDQ\RWKHU-DYDFODVVDQG \RXFDQWHVWLWZLWKRXW7RPFDW %XLOGDQGWHVWWKHPRGHO 0RGHOVFDQEHH[WUHPHO\FRPSOLFDWHG7KH\RIWHQLQYROYHFRQQHFWLRQVWROHJDF\ GDWDEDVHVDQGFDOOVWRFRPSOH[EXVLQHVVORJLF+HUH¶VRXUVRSKLVWLFDWHGUXOH EDVHGH[SHUWV\VWHPIRUWKHEHHUDGYLFH SDFNDJHFRPH[DPSOHPRGHO LPSRUWMDYDXWLO SXEOLFFODVV%HHU([SHUW^ SXEOLF/LVWJHW%UDQGV6WULQJFRORU^ /LVWEUDQGV QHZ$UUD\/LVW LIFRORUHTXDOV³DPEHU´^ EUDQGVDGG³-DFN$PEHU´ EUDQGVDGG³5HG0RRVH´ ` HOVH^ EUDQGVDGG³-DLO3DOH$OH´ EUDQGVDGG³*RXW6WRXW´ ` UHWXUQEUDQGV ` ` Notice how weÕve captured complex, expert knowledge of the beer paradigm using advanced conditional expressions. FGEHHU9 MDYDFFODVVSDWK8VHUVEHUW$SSOLFDWLRQVWRPFDWFRPPRQOLE VHUYOHWDSLMDUFODVVHVGFODVVHVVUFFRPH[DPSOHPRGHO%HHU([SHUWMDYD )LOH(GLW:LQGRZ+HOS6NDWHERDUG DonÕt forget to change this to use YOUR speciÞc path to the tomcat home. WKHPRGHOFODVV Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited. KDQGVRQ09& \RXDUHKHUH  -VPIVKQVO\PM[MZ^TM\\WKITT\PMUWLMT [W\PI\_MKIVOM\:-)4IL^QKM )NTHISVERSIONTWOSERVLETWELLENHANCETHEDO0OSTMETHODTO CALLTHEMODELFORADVICEVERSIONTHREEWILLMAKETHEADVICECOME FROMA*304HECODECHANGESARETRIVIALBUTTHEIMPORTANTPARTIS UNDERSTANDINGTHEREDEPLOYMENTOFTHEENHANCEDWEBAPP9OUCAN TRYTOWRITETHECODERECOMPILEANDDEPLOYONYOUROWNORYOU CANTURNTHEPAGEANDFOLLOWALONG (QKDQFHWKHVHUYOHWYHUVLRQWZR )RUJHWDERXWVHUYOHWVIRUDPLQXWHOHW·VMXVWWKLQN-DYD:KDW DUHWKHVWHSVZHKDYHWRWDNHWRDFFRPSOLVKWKHIROORZLQJ" (QKDQFHWKHGR3RVWPHWKRGWRFDOOWKHPRGHO &RPSLOHWKHVHUYOHW 'HSOR\DQGWHVWWKHXSGDWHGZHEDSS 6KDUSHQ \RXU SHQFLO public class BeerSelect extends HttpServlet { Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.  FKDSWHU SDFNDJHFRPH[DPSOHZHE LPSRUWFRPH[DPSOHPRGHO LPSRUWMDYD[VHUYOHW LPSRUWMDYD[VHUYOHWKWWS LPSRUWMDYDLR LPSRUWMDYDXWLO SXEOLFFODVV%HHU6HOHFWH[WHQGV+WWS6HUYOHW^ SXEOLFYRLGGR3RVW+WWS6HUYOHW5HTXHVWUHTXHVW    +WWS6HUYOHW5HVSRQVHUHVSRQVH WKURZV,2([FHSWLRQ6HUYOHW([FHSWLRQ^  UHVSRQVHVHW&RQWHQW7\SH³WH[WKWPO´  3ULQW:ULWHURXW UHVSRQVHJHW:ULWHU RXWSULQWOQ³%HHU6HOHFWLRQ$GYLFHEU!´  6WULQJF UHTXHVWJHW3DUDPHWHU³FRORU´   %HHU([SHUWEH QHZ%HHU([SHUW /LVWUHVXOW EHJHW%UDQGVF ,WHUDWRULW UHVXOWLWHUDWRU ZKLOHLWKDV1H[W^ RXWSULQW³EU!WU\³LWQH[W ` ` ` ;MZ^TM\^MZ[QWV\_WKWLM 2EMEMBERTHEMODELISJUSTPLAINOLD*AVASOWECALLITLIKEWEDCALLANY OTHER*AVAMETHODINSTANTIATETHEMODELCLASSANDCALLITSMETHOD Instantiate the BeerExpert class and call getBrands(). Print out the advice (beer brand items in the ArrayList returned from the model). In the Þnal (third) version, the advice will be printed from a JSP instead of the servlet. DonÕt forget the import for the package that BeerExpert is in. WeÕre modifying the original servlet, not making a new class. FDOOLQJWKHPRGHOIURPWKHVHUYOHWFRQWUROOHU Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited. KDQGVRQ09& \RXDUHKHUH  3Ma[\MX[NWZ[MZ^TM\^MZ[QWV\_W 7EHAVETWOMAINTHINGSTODORECOMPILETHESERVLETAND DEPLOYTHEMODELCLASS :H¶OOXVHWKHVDPHFRPSLOHUFRPPDQGWKDWZHXVHG ZKHQZHEXLOWWKH¿UVWYHUVLRQRIWKHVHUYOHW &RPSLOLQJWKHVHUYOHW 'HSOR\LQJDQGWHVWLQJWKHZHEDSS 1RZLQDGGLWLRQWRWKHVHUYOHWZHDOVRKDYHWRGHSOR\WKHPRGHO 7KHNH\VWHSVDUH 0RYHDFRS\RIWKHVHUYOHWFODVV¿OHWR %HHUY:(%,1)FODVVHVFRPH[DPSOHZHE 7KLVUHSODFHVWKHYHUVLRQRQHVHUYOHWFODVV¿OH 0RYHDFRS\RIWKHPRGHO¶VFODVV¿OHWR %HHUY:(%,1)FODVVHVFRPH[DPSOHPRGHO 6KXWGRZQDQGUHVWDUWWRPFDW 7HVWWKHDSSYLDIRUPKWPO WKH¿QDOEURZVHURXWSXWVKRXOGEH VRPHWKLQJOLNH  %HHU6HOHFWLRQ$GYLFH  WU\-DFN$PEHU  WU\5HG0RRVH FGEHHU9 MDYDFFODVVSDWK8VHUVEHUW$SSOLFDWLRQVWRPFDWFRPPRQOLE VHUYOHWDSLMDUFODVVHVGFODVVHVVUFFRPH[DPSOHZHE%HHU6HOHFWMDYD )LOH(GLW:LQGRZ+HOS3OD\*R ZHEDSSV %HHUY :(%,1) ZHE FODVVHV FRP H[DPSOH      %HHU6HOHFWFODVV WRPFDW PRGHO      %HHU([SHUWFODVV FGWRPFDW ELQVKXWGRZQVK ELQVWDUWXSVK )LOH(GLW:LQGRZ+HOS6HOO+LJK KWWSORFDOKRVW%HHUYIRUPKWPO Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.  FKDSWHU %HHU([SHUW FRP S RQHQ W %HHU([SHUW FRPSRQHQW :M^QM_\PMXIZ\QITTaKWUXTM\ML5>+ JMMZIL^QKM_MJIXXTQKI\QWV :KDW·VZRUNLQJVRIDU :KDWZH:$17 &O LH Q W 7KHEURZVHUVHQGVWKH UHTXHVWGDWDWRWKH&RQWDLQHU 7KH&RQWDLQHUILQGVWKH FRUUHFWVHUYOHWEDVHGRQWKH 85/DQGSDVVHVWKHUHTXHVWWR WKHVHUYOHW 7KHVHUYOHWFDOOVWKH %HHU([SHUWIRUKHOS 7KHH[SHUWFODVVUHWXUQVDQ DQVZHUZKLFKWKHVHUYOHWDGGV WRWKHUHTXHVWREMHFW 7KHVHUYOHWIRUZDUGVWKH UHTXHVWWRWKH-63 7KH-63JHWVWKHDQVZHU IURPWKHUHTXHVWREMHFW 7KH-63JHQHUDWHVDSDJH IRUWKH&RQWDLQHU 7KH&RQWDLQHUUHWXUQVWKH SDJHWRWKHKDSS\XVHU     &RQWDLQHU     UHTXHVW KWPO! KHDG! KHDG! ERG\!  ERG\! KWPO! UHVXOWMVS   VHUYOHW  &OLHQW :HE EURZVHU 7KHEURZVHUVHQGVWKH UHTXHVWGDWDWRWKH&RQWDLQHU 7KH&RQWDLQHUILQGVWKH FRUUHFWVHUYOHWEDVHGRQWKH 85/DQGSDVVHVWKHUHTXHVWWR WKHVHUYOHW 7KHVHUYOHWFDOOVWKH %HHU([SHUWIRUKHOS 7KHVHUYOHWRXWSXWVWKH UHVSRQVHZKLFKSULQWVWKH DGYLFH 7KH&RQWDLQHUUHWXUQVWKH SDJHWRWKHKDSS\XVHU   &RQWDLQHU ORJLF &RQWDLQHU   VHUYOHW   WKH09&DSS Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited. KDQGVRQ09& \RXDUHKHUH  #SDJHLPSRUW ´MDYDXWLO´! KWPO! ERG\! KDOLJQ ´FHQWHU´!%HHU5HFRPPHQGDWLRQV-63K! S!  /LVWVW\OHV /LVWUHTXHVWJHW$WWULEXWH³VW\OHV´ ,WHUDWRULW VW\OHVLWHUDWRU ZKLOHLWKDV1H[W^ RXWSULQW³EU!WU\³LWQH[W ` ! ERG\! KWPO! +ZMI\M\PM2;8¹^QM_º\PI\OQ^M[\PMIL^QKM $ONTGETYOURHOPESUP9OUREGOINGTOHAVETOWAITFORAFEW CHAPTERSBEFOREWEREALLYSTARTTALKINGABOUT*30S4HIS*30ISNT ACTUALLYAPARTICULARLYGOODONEEITHERBECAUSEOFITSSCRIPTLETCODE WHICHWELLTALKABOUTLATERINTHEBOOK&ORNOWITSHOULDBEPRETTY EASYTOREADANDIFYOUWANTTOEXPERIMENTALITTLEGOFORIT!LTHOUGH WECOULDTESTTHIS*30NOWFROMTHEBROWSERWELLWAITUNTILAFTERWE MODIFYTHESERVLETVERSIONTHREETOSEEIFITWORKS This is a Òpage directiveÓ (weÕre thinking itÕs pretty obvious what this one does). Some standard Java sitting inside <% %> tags (this is known as scriptlet code). Some standard HTML (which is known as Òtemplate textÓ in the JSP world). +HUH·VWKH-63 Here weÕre getting an attribute from the request object. A little later in the book, weÕll explain everything about attributes and how we managed to get the request object 'HSOR\LQJWKH-63 :HGRQ¶WFRPSLOHWKH-63WKH&RQWDLQHUGRHVWKDWDW¿UVWUHTXHVW %XWZHGRKDYHWR 1DPHLW³UHVXOWMVS´ 6DYHLWLQWKHGHYHORSPHQWHQYLURQPHQWLQZHE 0RYHDFRS\RILWWRWKHGHSOR\PHQWHQYLURQPHQWLQ%HHUY ZHEDSSV %HHUY WRPFDW    ! UHVXOWMVS  KWPO! ERG\!  ERG\! KWPO! IRUPKWPO Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1/2004 User number: 747221 Copyright 2007, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited. [...]...Chapter 3 Mini MVC Tutorial Chapter 3 Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with... Service is strictly prohibited Chapter 3 Mini MVC Tutorial Chapter 3 Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with... of Service is strictly prohibited Chapter 4 Being a Servlet Chapter 4 Being a Servlet Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with... of Service is strictly prohibited Chapter 4 Being a Servlet Chapter 4 Being a Servlet Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with... of Service is strictly prohibited Chapter 4 Being a Servlet Chapter 4 Being a Servlet Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with... of Service is strictly prohibited Chapter 4 Being a Servlet Chapter 4 Being a Servlet Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with... of Service is strictly prohibited Chapter 4 Being a Servlet Chapter 4 Being a Servlet Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with... of Service is strictly prohibited Chapter 4 Being a Servlet Chapter 4 Being a Servlet Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with... of Service is strictly prohibited Chapter 4 Being a Servlet Chapter 4 Being a Servlet Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with... of Service is strictly prohibited Chapter 4 Being a Servlet Chapter 4 Being a Servlet Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly Prepared for Stephen Goss, Safari ID: stephengoss@gmx.net Print Publication Date: 8/1 /20 04 User number: 74 722 1 Copyright 20 07, Safari Books Online, LLC This PDF is exclusively for your use in accordance with . the JSP to use. Notice the JSP is looking for ÒstylesÓ. Instantiate a request dispatcher for the JSP. Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By. ! ERG! KWPO! &RQWDLQHU &RQWDLQHU &RQWDLQHU &RQWDLQHU QDP U Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly. information. VHUYOHWFRQWUROOHUYHUVLRQRQH Chapter 3. Mini MVC Tutorial Chapter 3. Mini MVC Tutorial Head First Servlets and JSP By Bert Bates, Kathy Sierra, Bryan Basham ISBN: 0596005407 Publisher: O'Reilly

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