You are on page 1of 5
FOR PRIVATE CIRCULATION ONLY.RE-DESIGNED FOR USIT B.Tech STUDENTS. Agenda + Basic syntax + Types of JSP scripting elements + Expressions + Predefined variables + Scriptlets + Declarations Uses of JSP Constructs Smale. Script Application * SCriD + Script 1g elements calling servlet rectly elements caling seret code indirectly (by means of utility classes) + Beans + Customtags 5 SeavelJSP combo (MVC), Sage," Wath beans and possibly custom tags Design Strategy: Limit Java Code in JSP Pages + You have two options = Put 5 ines Java code dinetly i the JSP page Pat those 25 lines ina separate Java class an pt | line nthe JSP page tat awoke: it + Why is the second option much better? = Development. You wate the separate clas ia Java xwzomment (editor orIDE), sot an HTML exvoument — Debugging Ifyou lave syntax ers, you see thers raven atcompl ne Sample prt statement can — Tetng You canvrnite atest uti with loop that O{000 test ane seapply it after each change — Reuse. You cane the same clas from liple pages Basic Syntax + HTML Text = — Passed though to client Really tamed ino servet cole ‘hatlooks ike out pratBbh; + HTML Comments <1 Comment —> ~ Same as other HTML: passed Ywough to lint + JSP Comments = <%-Conunent = Wot sent to chant - To get <% in output, use <\% FOR PRIVATE CIRCULATION ONLY.RE-DESIGNED FOR USIT B.Tech STUDENTS. FOR PRIVATE CIRCULATION ONLY.RE-DESIGNED FOR USIT B.Tech STUDENTS. Types of Scripting Elements + Expressions —Fomat Java Expessionshsp expression CEM venion sot supported by Tomeat 3 Unt ISP 12, Pervar nue not egued fo aupyontat Even the you ‘anno nic veins wath angle JSP/Serviet Correspondence iginal JSP vnaer + Possible resulting serviet code public void _jepservioe (Reepservietnaquest ra Example Using JSP Expressions FOR PRIVATE CIRCULATION ONLY.RE-DESIGNED FOR USIT B.Tech STUDENTS. FOR PRIVATE CIRCULATION ONLY.RE-DESIGNED FOR USIT B.Tech STUDENTS. Predefined Variables + request = The HtyServatRequert (et angunent to senvceldoGet) + response ~ The HtpServetResponse 2nd ag to serviceldaGet) + out = The Whiter (a buffined version of type Jep\Wits) used fo Sena output fo the lent + session = The HtpSecsion aesociatd vith the request (lees disabled with he session attabute of he page ditectis) |* application ~ The SeyeetContext (for shaving data) 2s obtained via eetSerietContent) JSP Scriptlets + Format =< lava Code Yo + Result = Cole isicered verbatim into servlets jepService Stang queryData = request getQuar6 ting entpaln( Atacied GETant* quence); ve response seKConten Type “textpain’); ¥° + XMIL-compatible syntax ~ lava Codechspsenipteb> JSP Declarations + Format = <1 Java Code Yo + Result = Code is invested veibatisn no serve’ class defiition ctbide of any existing methods + Examples = 224 private vod someMthed(.)(..) %- + Design consideration — Fields ae clearly wsefal For mete, it i ually better to define the mth ina separate Java clas | XML-compatible syntax = Java Coles liop declan Example Using JSP Declarations “IDOSETS ET am Wo 4.0 emsieen//or> Serecreenc/ere > “SEibsae pectarationsc/m> FOR PRIVATE CIRCULATION ONLY.RE-DESIGNED FOR USIT B.Tech STUDENTS.

You might also like