Top Banner
JSP Jsp is a web technology function which is used to develop server side web components. Jsp will be used in presentation layer. Complete jsp life cycle will be taken care by web container. Jsp page is combination of HTML elements and JSP elements. Following is the list of JSP elements: ---------- 1. Scripting elements Scriplets Expressions Declarations 2. Directives Page directives Include directives taglib directives 3. Standard elements <jsp:include> <jsp:forward> <jsp:param> <jsp:useBean> <jsp:setProperty> <jsp:getProperty> 4. Custom elements(Tags) Syntax: ---------- <% ---- ---- ---- ---- ---- %> Scriplets is used to write any valid java statement. All the elements inside the Scriplets must be terminated by semicolon. Example: -------- <% int a=10; out println(a); // Implicit object %> All the statements inside the Scriplets will be placed inside the service() method of translated servlet. Scripting Elements Expression Information About JSP by JLC www.jlcindia.c om [email protected]
33
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

JSP Jsp is a web technology function which is used to develop server side web components. Jsp will be used in presentation layer. Complete jsp life cycle will be taken care by web container. Jsp page is combination of HTML elements and J! elements."ollowing is the list of J! elements# $$$$$$$$$$1. Scripting elements criplets %&pressions 'eclarations2. Directives !age directives (nclude directives taglib directives3. Standard elements )jsp#include* )jsp#forward* )jsp#param* )jsp#use+ean* )jsp#set!roperty* )jsp#get!roperty*,. Custom elements-Tags.Syntax: ----------)/$$$$ $$$$$$$$$$$$ $$$$/* criplets is used to write any valid java statement. 0ll the elements inside the criplets must be terminated by semicolon. %&ample# $$$$$$$$)/ int a1234out println-a.455 (mplicit object/* 0ll the statements inside the criplets will be placed inside the service-. method of translated servlet.Syntax# $$$$$$$$$$$$$$$$$$)/1e&p /*%&p#$$$$$)/16sri6/*)/1a/*)/1obj.m2-.4/* 7-invalid. %&pression is a short$cut form of out.println. Scripting ElementsExpressionn!ormation "#out JSP #y J$C%%%.&lcindia.comra&ivs'1(1)gmail.com 0ll the e&pression inside the J!8s will be placed inside the service-. method of translated servlet .ynta$$$$$$$$$$)/ 9$$$$$$$$$$$ $$$$$ $$$$$$$$$ /* (t is used to write variable declaration and method definition. Java statement are not allowed inside the declaration all the declaration inside the J! will be placed directly inside the translated servlet class and outside the service-. method.%&p# $$$$$$$$$$)/ 9 :oid m2-.;ystem.out.println-4:oid m2-.;ystem.out.println-&.4ystem.out.println->>>P4JspGriter out1pageConte&t.getCut-.4if-sid.eAuals-P>>P..;out.write-P)table border1D bgcolor1cyan*P.4out.write-P)tr*P.4out.write-P)td*id)5td*P.4out.write-P)td*PUsidUP)5td*P.4out.write-P)5tr*P.4out.write-P)tr*P.4out.write-P)td*name)5td*P.4out.write-P)td*PUsnameUP)5td*P.4out.write-P)5tr*P.4out.write-P)tr*P.4Enter sid -----Searc'ing out.write-P)tr*P.4out.write-P)td*!hone)5td*P.4out.write-P)td*PUphoneUP)5td*P.4out.write-P)5tr*P.4out.write-P)5table*P.4=else;out.write-P)h2*tudent not foundP.4==catch-%&ception e.;ystem.out.println-e.4=return %:0LL!0W%4==)taglib*)tlib$uri*G%+$(K"5jlc.tld)tlib$uri*)tlib$location*G%+$(K"5jlc.tld)5tlib$location*)5taglib*7e#.xml S'o%Student8ag.&ava Jlc.tldout.write-P)td*%mail)5td*P.4out.write-P)td*PUemailUP)5td*P.4out.write-P)5tr*P.4continue To simplify the developer task NK has implemented some custom tags for the commonly used that scenario .0s a jsp developer we can use the JTL tag directly in the J!.(n the JTL we have following four types of tags JTL core tags JTL formatting tag JTL &ml5&sl tag JTL sAl tags-not use directly in J!.JTL core tags#$$$$$$$$$$$$$$$$$ To use JTL tag in J! you need to write the following taglib directive in the J!.)/J taglib uri1http#55java.sun.com5jsp5jstl5core prefi&16sd6/* 55prefi&16some thing6 Tou should copy the following two jar file in your web application lib folder.JTL.jar tandard.jar 0fter copy the other side to lib restart the server Following are the list of JSTL core tags )sd#set* )sd#remove* )sd#out* )sd#if* )sd#choose* )sd#when* )sd#otherwise* )sd#for%ach* )sd#import* )sd#catch* )sd#param*Example# $$$$$$$$$)/J page is%L(gnored1PfalseP/*)/J taglib uri1Phttp#55java.sun.com5jsp5jstl5coreP prefi&1PsdP/*)sd#set var1PemailP scope1PsessionP value1PsriJsd.comP5*)h2*%mail#X;email=)br*)sd#remove var1PemailP scope1PsessionP5*%mail#X;email=)br*)sd#set var1PsnameP scope1PreAuestP value1PsriP5*name#)sd#out var1PsnameP5*name#X;sname=)sd#if test1PX;sname eA YsriY=P*this student name is srinivas...)5sd#if*)sd#if test1PX;sname ne YsriY=P*this student name isnot srinivas...)5sd#if*JS8$JSP Standard 8ag $i#rary et tag is used to declare a variable to the given name and initialiMed the variable with the given value and stores the variable in specified scope. @emove tag is used to remove the specified variable from specified scope. Cut tag is used to display the value of specified variable. (f tag is used to perform simple conditional checks.Example #$$$$$)/J page is%L(gnored1PfalseP/*)/J taglib uri1Phttp#55java.sun.com5jsp5jstl5coreP prefi&1PsdP/*)sd#set var1PsidP scope1PsessionP value1P>>P5*)font color1PredP*id#X;sid=)br*)5font*)sd#choose*)sd#when test1PX;sid eA Y>>Y=P*)h2*student id is >>)5h2*)5sd#when*)sd#when test1PX;sid eA YQQY=P*)h2*student id is QQ)5h2*)5sd#when*)sd#when test1PX;sid eA YZZY=P*)h2*student id is ZZ)5h2*)5sd#when*)sd#otherwise*)h2* student id is unknown)5h2*)5sd#otherwise*)5sd#choose*ynta& for %L# $$$$$$$$X;object name# object name=0ny valid %L implicit object0ny parameter or header or cookie or attribute name "ollowing are the list of %L implicit objects #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ !aram !aram:alues @eAuestcope !agecope essioncope 0pplicationcope ?.pageConte&t (na J! by default scripting elements will be unable and %L statement5e&pression will be disabled. To enable the %L e&pression in J! you need to use following page directives)/J page is%L(gnored16false6/*Implement the following core tag with the given attributesCutname%L-%&pression Language .?uestionetmore value scope@emovename scope(fcheck-some condition.y.&sp %it' E$;iles re>uired :---------------- jlc.tld JspNtil.java CutTag.java @emoveTag.java etTag.java test.jsp web.&ml &lc.tld)S&ml version1P2.3P encoding1PNT"$QPS*)9'CCTT!% taglib !N+L(C P$55un MicrosystemsB (nc.55'T' J! Tag Library 2.255%KP Phttp#55java.sun.com5jDee5dtds5web$jsptaglibraryL2L2.dtdP*x.&sp )taglib*)tlibversion*2.3)5tlibversion*)jspversion*2.2)5jspversion*)uri*5G%+$(K"5jlc.tld)5uri*)tag*)name*set)5name*)tagclass*com.jlc.etTag)5tagclass*)bodycontent*empty)5bodycontent*)attribute*)name*name)5name*)reAuired*true)5reAuired*)rte&prvalue*true)5rte&prvalue*y.jsp with scriptlet)5attribute*)attribute*)name*value)5name*)reAuired*true)5reAuired*)rte&prvalue*true)5rte&prvalue*)5attribute*)attribute*)name*scope)5name*)5attribute*)5tag*Continue )tag*)name*remove)5name*)tagclass*com.jlc.@emoveTag)5tagclass*)bodycontent*empty)5bodycontent*)attribute*)name*name)5name*)reAuired*true)5reAuired*)tag*)name*out)5name*)tagclass*com.jlc.CutTag)5tagclass*)bodycontent*empty)5bodycontent*)attribute*)name*name)5name*)reAuired*true)5reAuired*Kame is X;param.sn=%mail is X;param.em=!hone is X;param.ph=K%mail !hone Su#mit)/tring sn1reAuest.get!arameter->P.4s2.setname-PsriP.4s2.set%mail-PsJs.comP.4s2.set!hone-P>>>>P.4tudent sD1new tudent-.4sD.setid-PQQP.4sD.setname-PvasP.4sD.set%mail-PvJs.comP.4sD.set!hone-PQQQQP.40rrayList al1new 0rrayList-.4al.add-s2.4al.add-sD.4session.set0ttribute-P0LPBal.4HashMap hm21new HashMap-.4hm2.put-PaPBPaaaaP.4hm2.put-PbPBPbbbbP.4hm2.put-PcPBPccccP.4HashMap hmD1new HashMap-.4hmD.put-P&PBP&&&&P.4hmD.put-PyPBPyyyyP.4hmD.put-PMPBPMMMMP.40rrayList al21new 0rrayList-.4al2.add-hm2.4al2.add-hmD.4session.set0ttribute-P0L2PBal2.4/*)h2*tudent info)br*)sd#for%ach var1PstuP items1PX;0L=P*tudent ('#;stu.sid=)br*name#X;stu.sname=)br*%mail#X;stu.email=)br*!hone#X;stu.phone=)br*)5sd#for%ach*)h2*from list of maps)br*)sd#for%ach var1PmapP items1PX;0L2=P*)sd#for%ach var1P&P items1PX;map=P*X;&=)br*X;map]PX;&=P^=)5sd#for%ach*)5sd#for%ach*J! +T JLCwww.jlcindia.comlogon pleaseramansh232Jgmail.com