Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 74 trang
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 %HHUY6HOHFW%HHUGR +773 +RVWZZZZLFNHGO\VPDUWFRP 8VHU$JHQW0R]LOOD0DFLQWRVK8 33&0DF26;0DFK2HQ86UY *HFNR1HWVFDSH $FFHSWWH[W[PODSSOLFDWLRQ [PODSSOLFDWLRQ[KWPO[POWH[W KWPOT WH[WSODLQT YLGHR[ PQJLPDJHSQJLPDJHMSHJLPDJH JLIT T 'LDQHÀOOVRXWWKHIRUPDQGKLWVVXEPLW7KHEURZVHU JHQHUDWHVWKHUHTXHVW85/ %HHUY6HOHFW%HHUGR The web app context root. The logical resource name. &RQWDLQHU &OLHQW 7KH&RQWDLQHUVHDUFKHVWKH'' DQGÀQGVDVHUYOHWPDSSLQJ! ZLWKDXUOSDWWHUQ!WKDW PDWFKHV 6HOHFW%HHUGRZKHUH WKHVODVKUHSUHVHQWVWKH FRQWH[WURRWRIWKHZHEDSSDQG 6HOHFW%HHUGRLVWKH ORJLFDO QDPH RIDUHVRXUFH &RQWDLQHU ZHEDSS! VHUYOHW! VHUYOHWQDPH! &K%HHU VHUYOHWQDPH! VHUYOHWFODVV! FRPH[DPSOHZHE%HHU6HOHFW VHUYOHWFODVV! VHUYOHW! VHUYOHWPDSSLQJ! VHUYOHWQDPH! &K%HHU VHUYOHWQDPH! XUOSDWWHUQ! 6HOHFW%HHUGR XUOSDWWHUQ! VHUYOHWPDSSLQJ! ZHEDSS! &RQWDLQHU 7KH&RQWDLQHUVHHVWKDWWKHVHUYOHW QDPH!IRUWKLVXUOSDWWHUQ!LV´&K %HHUµ%XWWKDWLVQ·WWKHQDPHRIDQ DFWXDOVHUYOHWFODVVÀOH´&K%HHUµLV WKHQDPHRID VHUYOHW QRWDVHUYOHW FODVV 7RWKH&RQWDLQHUDVHUYOHWLVVRPHWKLQJ QDPHGLQWKH''XQGHUDVHUYOHW!WDJ 7KHQDPHRIWKHVHUYOHWLVVLPSO\WKH QDPHXVHGLQWKH''VRWKDWRWKHU SDUWVRIWKH''FDQPDSWRLW 5IXXQVO\PMTWOQKITVIUM\WI[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. VHUYOHWPDSSLQJ 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. KDQGVRQ09& \RXDUHKHUH ZHEDSS! VHUYOHW! VHUYOHWQDPH! &K%HHU VHUYOHWQDPH! VHUYOHWFODVV! FRPH[DPSOHZHE%HHU6HOHFW VHUYOHWFODVV! VHUYOHW! VHUYOHWPDSSLQJ! VHUYOHWQDPH! &K%HHU VHUYOHWQDPH! XUOSDWWHUQ! 6HOHFW%HHUGR XUOSDWWHUQ! VHUYOHWPDSSLQJ! ZHEDSS! H! E ! 7KH&RQWDLQHUORRNVLQVLGHWKH VHUYOHW!WDJVIRUVRPHWKLQJZLWK WKHVHUYOHWQDPH!´&K%HHUµ 7KH&RQWDLQHUXVHVWKH VHUYOHWFODVV!LQWKHVHUYOHW! WDJWRNQRZZKLFKVHUYOHWFODVV LVUHVSRQVLEOHIRUKDQGOLQJWKLV UHTXHVW,IWKHVHUYOHWKDV QRWEHHQLQLWLDOL]HGWKHFODVV LVORDGHGDQGWKHVHUYOHWLV LQLWLDOL]HG 7KH&RQWDLQHUVWDUWVDQHZWKUHDGWR KDQGOHWKHUHTXHVWDQGSDVVHVWKH UHTXHVWWRWKHWKUHDGWRWKHVHUYOHW·V VHUYLFHPHWKRG VHUYOHW 7KH&RQWDLQHUVHQGVWKHUHVSRQVHWKURXJKWKH :HE6HUYHURIFRXUVHEDFNWRWKHFOLHQW &OLHQW VHUYOHW UHTXHVW +7732. KWPO! KHDG! KHDG! ERG\! LPJVUF ! ERG\! KWPO! UHVSRQVH +7732. KWPO! KHDG! KHDG! ERG\! LPJVUF ! 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 <PMNQZ[\^MZ[QWVWN\PMKWV\ZWTTMZ[MZ^TM\ SDFNDJHFRPH[DPSOHZHE LPSRUWMDYD[VHUYOHW LPSRUWMDYD[VHUYOHWKWWS LPSRUWMDYDLR SXEOLFFODVV%HHU6HOHFWH[WHQGV+WWS6HUYOHW^ SXEOLFYRLGGR3RVW+WWS6HUYOHW5HTXHVWUHTXHVW +WWS6HUYOHW5HVSRQVHUHVSRQVH WKURZV,2([FHSWLRQ6HUYOHW([FHSWLRQ^ UHVSRQVHVHW&RQWHQW7\SH³WH[WKWPO´ 3ULQW:ULWHURXW UHVSRQVHJHW:ULWHU RXWSULQWOQ³%HHU6HOHFWLRQ$GYLFHEU!´ 6WULQJF UHTXHVWJHW3DUDPHWHU³FRORU´ RXWSULQWOQ³EU!*RWEHHUFRORU³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. /URPLANISTOBUILDTHESERVLETINSTAGESTESTINGTHEVARIOUSCOMMUNICATION LINKSASWEGO)NTHEENDREMEMBERTHESERVLETWILLACCEPTAPARAMETERFROM THEREQUESTINVOKEAMETHODONTHEMODELSAVEINFORMATIONINAPLACETHE *30CANlNDANDFORWARDTHEREQUESTTOTHE*30"UTFORTHISlRSTVERSIONOUR GOALISJUSTTOMAKESURETHATTHE(4-,PAGECANPROPERLYINVOKETHESERVLET ANDTHATTHESERVLETISRECEIVINGTHE(4-,PARAMETERCORRECTLY HttpServlet extends GenericServlet, which implements the Servlet interface LQWHUIDFH!! MDYD[VHUYOHW6HUYOHW MDYD[VHUYOHW*HQHULF6HUYOHW MDYD[VHUYOHWKWWS+WWS6HUYOHW LQWHUIDFH!! MDYD[VHUYOHWKWWS+WWS6HUYOHW5HTXHVW LQWHUIDFH!! MDYD[VHUYOHW6HUYOHW5HTXHVW LQWHUIDFH!! MDYD[VHUYOHWKWWS+WWS6HUYOHW5HVSRQVH LQWHUIDFH!! MDYD[VHUYOHW6HUYOHW5HVSRQVH 6HUYOHWFRGH .H\$3,V WeÕre not giving back advice here, just displaying test information. VHUYOHWFRQWUROOHUYHUVLRQRQH 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. KDQGVRQ09& \RXDUHKHUH /KWEVEBUILTDEPLOYEDANDTESTEDOUR(4-,ANDWEVEBUILTANDDEPLOYEDOUR$$ WELLWEPUTTHEWEBXMLINTOTHEDEPLOYMENTENVIRONMENTBUTTECHNICALLYTHE$$ WONTBEDEPLOYEDUNTILWERESTART4OMCAT.OWITSTIMETOCOMPILETHElRSTVERSIONOF THESERVLETDEPLOYITANDTESTITVIATHE(4-,FORM.OWWELLRESTART4OMCATTOMAKE SURETHATIThSEESvTHEWEBXMLANDSERVLETCLASS +WUXQTQVOLMXTWaQVOIVL\M[\QVO\PMKWV\ZWTTMZ[MZ^TM\ &RPSLOLQJWKHVHUYOHW &RPSLOHWKHVHUYOHWZLWKWKHGÀDJWRSXWWKHFODVVLQWKHGHYHORSPHQWHQYLURQPHQW 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\LQJWKHVHUYOHW 7RGHSOR\WKHVHUYOHWPDNHDFRS\RIWKHFODVV¿OHDQGPRYHLWWRWKH %HHUY:(%,1)FODVVHVFRPH[DPSOHZHEGLUHFWRU\LQWKHGHSOR\PHQWVWUXFWXUH 7HVWLQJWKHVHUYOHW 5HVWDUWWRPFDW /DXQFK\RXUEURZVHUDQGJRWR KWWSORFDOKRVW%HHUYIRUPKWPO 6HOHFWDEHHUFRORUDQGKLW³6XEPLW´ ,I\RXUVHUYOHWLVZRUNLQJ\RXVKRXOG VHHWKHVHUYOHW¶VUHVSRQVHLQ\RXUEURZVHU DVVRPHWKLQJOLNH %HHU6HOHFWLRQ$GYLFH *RWEHHUFRORUEURZQ FG0\3URMHFWVEHHU9 MDYDFFODVVSDWK8VHUVEHUW$SSOLFDWLRQVWRPFDWFRPPRQOLE VHUYOHWDSLMDUFODVVHVGFODVVHVVUFFRPH[DPSOHZHE%HHU6HOHFWMDYD )LOH(GLW:LQGRZ+HOS8SGDWH%UDLQ FGWRPFDW ELQVKXWGRZQVK ELQVWDUWXSVK )LOH(GLW:LQGRZ+HOS6ODVKGRW0H ZHEDSSV %HHUY :(%,1) ZHE FODVVHV FRP H[DPSOH %HHU6HOHFWFODVV WRPFDW KWWSORFDOKRVW%HHUYIRUPKWPO 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 *]QTLQVOIVL\M[\QVO\PMUWLMTKTI[[ )N-6#THEMODELTENDSTOBETHEhBACKENDvOFTHEAPPLICATION)TSOFTENTHELEGACYSYSTEM THATSNOWBEINGEXPOSEDTOTHEWEB)NMOSTCASESITSJUSTPLAINOLD*AVACODEWITHNO KNOWLEDGEOFTHEFACTTHATITMIGHTBECALLEDBYSERVLETS4HEMODELSHOULDNTBETIEDDOWN TOBEINGUSEDBYONLYASINGLEWEBAPPSOITSHOULDBEINITSOWNUTILITYPACKAGES 7KHVSHFVIRUWKHPRGHO ,WVSDFNDJHVKRXOGEHFRPH[DPSOHPRGHO ,WVGLUHFWRU\VWUXFWXUHVKRXOGEH:(%,1)FODVVHVFRPPRGHO ,WH[SRVHVRQHPHWKRGJHW%UDQGVWKDWWDNHVDSUHIHUUHGEHHUFRORUDVD 6WULQJDQGUHWXUQVDQ$UUD\/LVWRIUHFRPPHQGHGEHHUEUDQGVDOVRDV6WULQJV %XLOGWKHWHVWFODVVIRUWKHPRGHO &UHDWHWKHWHVWFODVVIRUWKHPRGHO\HVEHIRUH\RXEXLOGWKHPRGHOLWVHOI<RX¶UHRQ \RXURZQKHUHZHGRQ¶WKDYHRQHLQWKLVWXWRULDO5HPHPEHUWKHPRGHOZLOOVWLOOEHLQWKH GHYHORSPHQWHQYLURQPHQWZKHQ\RX¿UVWWHVWLW²LW¶VMXVWOLNHDQ\RWKHU-DYDFODVVDQG \RXFDQWHVWLWZLWKRXW7RPFDW %XLOGDQGWHVWWKHPRGHO 0RGHOVFDQEHH[WUHPHO\FRPSOLFDWHG7KH\RIWHQLQYROYHFRQQHFWLRQVWROHJDF\ GDWDEDVHVDQGFDOOVWRFRPSOH[EXVLQHVVORJLF+HUH¶VRXUVRSKLVWLFDWHGUXOH EDVHGH[SHUWV\VWHPIRUWKHEHHUDGYLFH SDFNDJHFRPH[DPSOHPRGHO LPSRUWMDYDXWLO SXEOLFFODVV%HHU([SHUW^ SXEOLF/LVWJHW%UDQGV6WULQJFRORU^ /LVWEUDQGV QHZ$UUD\/LVW LIFRORUHTXDOV³DPEHU´^ EUDQGVDGG³-DFN$PEHU´ EUDQGVDGG³5HG0RRVH´ ` HOVH^ EUDQGVDGG³-DLO3DOH$OH´ EUDQGVDGG³*RXW6WRXW´ ` UHWXUQEUDQGV ` ` Notice how weÕve captured complex, expert knowledge of the beer paradigm using advanced conditional expressions. FGEHHU9 MDYDFFODVVSDWK8VHUVEHUW$SSOLFDWLRQVWRPFDWFRPPRQOLE VHUYOHWDSLMDUFODVVHVGFODVVHVVUFFRPH[DPSOHPRGHO%HHU([SHUWMDYD )LOH(GLW:LQGRZ+HOS6NDWHERDUG DonÕt forget to change this to use YOUR speciÞc path to the tomcat home. WKHPRGHOFODVV 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. KDQGVRQ09& \RXDUHKHUH -VPIVKQVO\PM[MZ^TM\\WKITT\PMUWLMT [W\PI\_MKIVOM\:-)4IL^QKM )NTHISVERSIONTWOSERVLETWELLENHANCETHEDO0OSTMETHODTO CALLTHEMODELFORADVICEVERSIONTHREEWILLMAKETHEADVICECOME FROMA*304HECODECHANGESARETRIVIALBUTTHEIMPORTANTPARTIS UNDERSTANDINGTHEREDEPLOYMENTOFTHEENHANCEDWEBAPP9OUCAN TRYTOWRITETHECODERECOMPILEANDDEPLOYONYOUROWNORYOU CANTURNTHEPAGEANDFOLLOWALONG (QKDQFHWKHVHUYOHWYHUVLRQWZR )RUJHWDERXWVHUYOHWVIRUDPLQXWHOHW·VMXVWWKLQN-DYD:KDW DUHWKHVWHSVZHKDYHWRWDNHWRDFFRPSOLVKWKHIROORZLQJ" (QKDQFHWKHGR3RVWPHWKRGWRFDOOWKHPRGHO &RPSLOHWKHVHUYOHW 'HSOR\DQGWHVWWKHXSGDWHGZHEDSS 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 SDFNDJHFRPH[DPSOHZHE LPSRUWFRPH[DPSOHPRGHO LPSRUWMDYD[VHUYOHW LPSRUWMDYD[VHUYOHWKWWS LPSRUWMDYDLR LPSRUWMDYDXWLO SXEOLFFODVV%HHU6HOHFWH[WHQGV+WWS6HUYOHW^ SXEOLFYRLGGR3RVW+WWS6HUYOHW5HTXHVWUHTXHVW +WWS6HUYOHW5HVSRQVHUHVSRQVH WKURZV,2([FHSWLRQ6HUYOHW([FHSWLRQ^ UHVSRQVHVHW&RQWHQW7\SH³WH[WKWPO´ 3ULQW:ULWHURXW UHVSRQVHJHW:ULWHU RXWSULQWOQ³%HHU6HOHFWLRQ$GYLFHEU!´ 6WULQJF UHTXHVWJHW3DUDPHWHU³FRORU´ %HHU([SHUWEH QHZ%HHU([SHUW /LVWUHVXOW EHJHW%UDQGVF ,WHUDWRULW UHVXOWLWHUDWRU ZKLOHLWKDV1H[W^ RXWSULQW³EU!WU\³LWQH[W ` ` ` ;MZ^TM\^MZ[QWV\_WKWLM 2EMEMBERTHEMODELISJUSTPLAINOLD*AVASOWECALLITLIKEWEDCALLANY OTHER*AVAMETHODINSTANTIATETHEMODELCLASSANDCALLITSMETHOD 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. FDOOLQJWKHPRGHOIURPWKHVHUYOHWFRQWUROOHU 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. KDQGVRQ09& \RXDUHKHUH 3Ma[\MX[NWZ[MZ^TM\^MZ[QWV\_W 7EHAVETWOMAINTHINGSTODORECOMPILETHESERVLETAND DEPLOYTHEMODELCLASS :H¶OOXVHWKHVDPHFRPSLOHUFRPPDQGWKDWZHXVHG ZKHQZHEXLOWWKH¿UVWYHUVLRQRIWKHVHUYOHW &RPSLOLQJWKHVHUYOHW 'HSOR\LQJDQGWHVWLQJWKHZHEDSS 1RZLQDGGLWLRQWRWKHVHUYOHWZHDOVRKDYHWRGHSOR\WKHPRGHO 7KHNH\VWHSVDUH 0RYHDFRS\RIWKHVHUYOHWFODVV¿OHWR %HHUY:(%,1)FODVVHVFRPH[DPSOHZHE 7KLVUHSODFHVWKHYHUVLRQRQHVHUYOHWFODVV¿OH 0RYHDFRS\RIWKHPRGHO¶VFODVV¿OHWR %HHUY:(%,1)FODVVHVFRPH[DPSOHPRGHO 6KXWGRZQDQGUHVWDUWWRPFDW 7HVWWKHDSSYLDIRUPKWPO WKH¿QDOEURZVHURXWSXWVKRXOGEH VRPHWKLQJOLNH %HHU6HOHFWLRQ$GYLFH WU\-DFN$PEHU WU\5HG0RRVH FGEHHU9 MDYDFFODVVSDWK8VHUVEHUW$SSOLFDWLRQVWRPFDWFRPPRQOLE VHUYOHWDSLMDUFODVVHVGFODVVHVVUFFRPH[DPSOHZHE%HHU6HOHFWMDYD )LOH(GLW:LQGRZ+HOS3OD\*R ZHEDSSV %HHUY :(%,1) ZHE FODVVHV FRP H[DPSOH %HHU6HOHFWFODVV WRPFDW PRGHO %HHU([SHUWFODVV FGWRPFDW ELQVKXWGRZQVK ELQVWDUWXSVK )LOH(GLW:LQGRZ+HOS6HOO+LJK KWWSORFDOKRVW%HHUYIRUPKWPO 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_\PMXIZ\QITTaKWUXTM\ML5>+ JMMZIL^QKM_MJIXXTQKI\QWV :KDW·VZRUNLQJVRIDU :KDWZH:$17 &O LH Q W 7KHEURZVHUVHQGVWKH UHTXHVWGDWDWRWKH&RQWDLQHU 7KH&RQWDLQHUILQGVWKH FRUUHFWVHUYOHWEDVHGRQWKH 85/DQGSDVVHVWKHUHTXHVWWR WKHVHUYOHW 7KHVHUYOHWFDOOVWKH %HHU([SHUWIRUKHOS 7KHH[SHUWFODVVUHWXUQVDQ DQVZHUZKLFKWKHVHUYOHWDGGV WRWKHUHTXHVWREMHFW 7KHVHUYOHWIRUZDUGVWKH UHTXHVWWRWKH-63 7KH-63JHWVWKHDQVZHU IURPWKHUHTXHVWREMHFW 7KH-63JHQHUDWHVDSDJH IRUWKH&RQWDLQHU 7KH&RQWDLQHUUHWXUQVWKH SDJHWRWKHKDSS\XVHU &RQWDLQHU UHTXHVW KWPO! KHDG! KHDG! ERG\! ERG\! KWPO! UHVXOWMVS VHUYOHW &OLHQW :HE EURZVHU 7KHEURZVHUVHQGVWKH UHTXHVWGDWDWRWKH&RQWDLQHU 7KH&RQWDLQHUILQGVWKH FRUUHFWVHUYOHWEDVHGRQWKH 85/DQGSDVVHVWKHUHTXHVWWR WKHVHUYOHW 7KHVHUYOHWFDOOVWKH %HHU([SHUWIRUKHOS 7KHVHUYOHWRXWSXWVWKH UHVSRQVHZKLFKSULQWVWKH DGYLFH 7KH&RQWDLQHUUHWXUQVWKH SDJHWRWKHKDSS\XVHU &RQWDLQHU ORJLF &RQWDLQHU VHUYOHW WKH09&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. KDQGVRQ09& \RXDUHKHUH #SDJHLPSRUW ´MDYDXWLO´! KWPO! ERG\! KDOLJQ ´FHQWHU´!%HHU5HFRPPHQGDWLRQV-63K! S! /LVWVW\OHV /LVWUHTXHVWJHW$WWULEXWH³VW\OHV´ ,WHUDWRULW VW\OHVLWHUDWRU ZKLOHLWKDV1H[W^ RXWSULQW³EU!WU\³LWQH[W ` ! ERG\! KWPO! +ZMI\M\PM2;8¹^QM_º\PI\OQ^M[\PMIL^QKM $ONTGETYOURHOPESUP9OUREGOINGTOHAVETOWAITFORAFEW CHAPTERSBEFOREWEREALLYSTARTTALKINGABOUT*30S4HIS*30ISNT ACTUALLYAPARTICULARLYGOODONEEITHERBECAUSEOFITSSCRIPTLETCODE WHICHWELLTALKABOUTLATERINTHEBOOK&ORNOWITSHOULDBEPRETTY EASYTOREADANDIFYOUWANTTOEXPERIMENTALITTLEGOFORIT!LTHOUGH WECOULDTESTTHIS*30NOWFROMTHEBROWSERWELLWAITUNTILAFTERWE MODIFYTHESERVLETVERSIONTHREETOSEEIFITWORKS 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·VWKH-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\LQJWKH-63 :HGRQ¶WFRPSLOHWKH-63WKH&RQWDLQHUGRHVWKDWDW¿UVWUHTXHVW %XWZHGRKDYHWR 1DPHLW³UHVXOWMVS´ 6DYHLWLQWKHGHYHORSPHQWHQYLURQPHQWLQZHE 0RYHDFRS\RILWWRWKHGHSOR\PHQWHQYLURQPHQWLQ%HHUY ZHEDSSV %HHUY WRPFDW ! UHVXOWMVS KWPO! ERG\! ERG\! KWPO! IRUPKWPO 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. VHUYOHWFRQWUROOHUYHUVLRQRQH 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