JSP Word Document
-
Upload
gone-harikrishna -
Category
Documents
-
view
230 -
download
0
Transcript of JSP Word Document
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 1/21
JSP
JSP Technology is used to create web application just like Servlet Technology. This page Contains Html
Tags & Jsp Tags.
Advantages:
Extension to Servlet: It is !tension to Servlet. "dditional to Servlet #eatures$ we can use implicit
objects$ prede#ined Tags$ !pressional %anguage & Custom Tags in Jsp$ that make Jsp evelopment easy.
Easy to Maintain: 'e can asily Separate our (usiness logic with )resentation logic. In Servlet$ we mi!
our (usiness logic with the )resentation logic.
Fast Development: I# we modi#y Jsp )age$ *o need to +ecompile & +edeploy.
Less Code than Servlet: 'e can use a lot o# tags such as action tags$ jstl$ custom tags$ % & implicit
,bjects etc. reduces the code.
Life Cycle: It #ollow these phases. jspInit-$ /jspService- & jspestroy- are li#e cycle methods.
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 2/21
0rom iag$ Jsp page is translated into Servlet by Jsp Translator. It is part o# 'eb server
responsible to translate the Jsp page into Servlet. "#ter Servlet page is compiled by the compiler & gets
converted into class #ile. "nd all the processes that happen in Servlet are per#ormed on Jsp later like
Initiali1ation$ committing response to the (rowser & estroy.
ranslation
Compilation
Classloading -class loaded by the classloader
!nstantiation -,bject o# 2enerated Servlet is created
!nitiali"ation - jspInit- is invoked by the container
#e$%est Processing -/jspService- is invoked by the container
Destroy - jspestroy-is invoked by the container
To +un a Simple JS) )age3
Start the Server
)ut the Jsp #ile in #older & deploy on the Server.
4isit the (rowser by the 5rl http366localhost3portno6conte!t+oot6jsp#ile
!3 http366localhost377776myapp6mine.jsp
8 There is no need o# directory structure i# you don9t have class #iles or tld #iles. 0or e!ample$ put jsp #iles
in a #older directly and deploy that #older. It will be running #ine. (ut i# you are using bean class$ Servletor tld #ile then directory structure is re:uired.
Directory Str%ct%re: Same as Servlet. ,utside the '(;I*0 #older or in any irectory.
JS) ")I Consists o# < )ackages3
java!.servlet.jsp
java!.servlet.jsp.tage!t
&avax'servlet'&sp: has < inter#aces and classes.
Jsp)age
HttpJsp)age
Classes
Jsp'riter
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 3/21
)ageConte!t
Jsp0actory
JspngineIn#o
Jsp!ception
Jsprror
JspPage: "ccording to JS) Spec$ all the 2enerated Servlet classes must implement the Jsp)age. It
!tends the Servlet inter#ace. )rovides < li#e cycle methods.
p%(lic void &sp!nit)*: It is invoked only once during the li#e cycle o# the JS) when JS) page is
re:uested #irstly. It is used to per#orm initiali1ation. It is same as the init- method o# Servlet inter#ace.
p%(lic void &spDestroy)*: It is invoked only once during the li#e cycle o# the JS) be#ore the JS)
page is destroyed. It can be used to per#orm some cleanup operation.
+ttpJspPage: )rovides on li#e cycle method. It e!tends Jsp)age inter#ace.
p%(lic void ,&spService)*: It is invoked each time when re:uest #or the JS) page comes to the
container. It is used to process the re:uest. The underscore / signi#ies that you cannot override this
method.
JSP in Eclipse -ith omcat
Create a ynamic web project
Create a jsp
Start Tomcat server & deploy the project
JSP Scriptlet ag: In Jsp$ java code can be written inside the jsp page using the scriptlet tag.
Elements: )rovides the ability to insert java code inside the jsp.
scriptlet tag: used to e!ecute java source code in Jsp.
Syn3 => java source code >?
!3 =html?=body?=> out.print-@'elcomeAB >?=6html?=6body?
expression tag: The code placed within JSP expression tag is written to the output stream o# the
response. So you need not write out.print- to write data. mainly used to print the values o# var or method.
Syn3 => statement >?
!3 =html?=body?=> @'elcomeA >?=6html?=6body?
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 4/21
declaration tag: used to declare #ields and methods. The code written inside the jsp declaration tag is
placed outside the service- o# auto generated Servlet. So doesnDt get memory at each re:uest.
Syn3 =>E 0ield or method declaration >?
i##3
Scriptlet Tag eclaration Tag
,nly declare variables not methods declare variables as well as methods
eclaration placed inside the /jspService-. eclaration is placed outside the /jspService-.
JSP !mplicit .(&ects: F ,bjects are there. These objects are created by the web containers that are
available to all the jsp pages.
o%t Jsp/riter
re$%est +ttpServlet#e$%est
response +ttpServlet#esponse
config ServletConfig
application ServletContext
session +ttpSession
pageContext PageContext
page .(&ect
exception hro-a(le
o%t: #or writing any data to the bu##er$ JS) provides out. It is the object o# Jsp'riter.
)rint'riter out response.get'riter-B
In Jsp$
=html?=body?=> out.print-@Today3 AGjava.util.Calender.getInstance-.getTime-B >?=6html?=6body?
re$%est: It is an Implicit object o# HttpServlet+e:uest i.e. created #or each jsp re:uest by the web
container. 5sed to get re:uest in#o such as parameter$ header in#o$ remote address$ server name$ server
port$ content type$ character encoding etc.
It can also be used to set$ get and remove attributes #rom the jsp re:uest scope.
=> String namere:uest.get)arameter-@unameAB
out.print-@welcome AGnameB >?
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 5/21
response: It is an Implicit object o# HttpServlet+esponse. The instance o# HttpServlet+esponse is created
by the web container #or each jsp re:uest.
used to add or manipulate response such as redirect response to another resource$ send error etc.
=> [email protected] >?
config: It is an Implicit object o# type ServletCon#ig. This object can be used to get initiali1ation
parameter #or a particular JS). The con#ig object is created by the web container #or each jsp page.
It is used to get initiali1ation parameter #rom the web.!ml #ile.
application: It is an implicit object o# type ServletConte!t. Instance o# ServletConte!t is created only
once by the web container when project or application is deployed on the server. This object can be used
to get initiali1ation parameter #rom con#iguration #ile-web.!ml. It can also be used to get$ set or remove
attribute #rom the application scope.
This initiali1ation parameter can be used by all jsp pages.
session: It is an Implicit object o# type HttpSession. 5se this object to set$ get or remove attribute or to
get session in#o.
pageContext: It is an Implicit object o# type )ageConte!t class. The pageConte!t object can be used to
set$ get or remove attribute #rom one o# the #ollowing scopes3
page
re:uest
session
application
page scope is the de#ault scope.
page: It is an Implicit object o# type ,bject class. This object is assigned to the re#erence o# auto
generated Servlet class.
,bject pagethisB
0or using this object it must be cast to Servlet type.
!3 => -HttpServletpage.log-@messageAB >?
Since it is o# type object it is less used bco1 you can use this object directly in jsp.
!3 => this.log-@messageAB >?
exception: It is an implicit object o# type java.langThrowable class. This object can be used to print the
e!ception. (ut it can only be used in rror pages.
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 6/21
JSP directives: messages that tells the web container how to translate a JS) page into
Corresponding Servlet.
page directive
include directive
taglib directive
Syn3 => directive attributeAvalueA >?
JSP page directive: de#ines attributes that apply to an entire JS) page.
Syn3 => page attributeAvalueA >?
Attri(%tes:
!mport: used to import class$ inter#ace or all the members o# a package.
contentype: de#ines the I-ultipurpose Internet ail !tension type o# the HTT) response. The
de#ault value is te!t6htmlBcharsetIS,;77F;KD.
extends: de#ines the parent class that will be inherited by the 2enerated Servlet. It is rarely used.
info: simply sets the in#o o# the Jsp page which is retrieved later by using getServletIn#o- o# Servlet
inter#ace.
(%ffer: sets the bu##er si1e in kbDs to handle output generated by the Jsp page. e#ault si1e is 7kb.
lang%age: speci#ies the scripting language used in the JS) page. e#ault value is @javaA.
isEL!gnored: 'e can ignore the !pression %anguage in jsp by the is%Ignored attribute. e#ault value
is #alse i.e. % is enabled by de#ault.
=> page is%IgnoredAtrueA >?66*ow % ignored
ishreadSafe: Servlet and JS) both are multithreaded. I# you want to control this behavior o# JS) page$
you can use isThreadSa#e attribute o# page directive. The value o# isThreadSa#e value is true. I# you make
it #alse$ the web container will seriali1e the multiple re:uests$ i.e. it will wait until the JS) #inishes
responding to a re:uest be#ore passing another re:uest to it.
=> page isThreadSa#eA#alseA >?
In this case$ web container generate the Servlet as3
public class Simple)age/jsp e!tends HttpJsp(ase implements SingleThreadodelL
M
N
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 7/21
errorPage: used to de#ine the error page$ i# e!ception occurs in the current page$ it will be redirected to
the error page.
isErrorPage: used to declare that current page is the error page.
The e!ception object can only be used in the error page.
JSP !ncl%de directive: used to include the contents o# any resource it may be jsp0html0te!t #ile. It
includes the original content o# the included resource at page translation time.
Advantage: code +eusability.
Syn3 => include #ileAresource*ameA >?
!3 => include #ileAinde!.htmlA >?
=> java.util.Calender.getInstance-.getTime- >?
It Includes the ,riginal Content$ So the "ctual page si1e grows at +untime.
JSP agli( directive: used to de#ine a tag library that de#ines many tags. 'e use T%-Tag %ibrary
escriptor #ile to de#ine the tags.
Syn3 => taglib uriAurio#thetaglibraryA pre#i!Apre#i!o#taglibraryA >?
!3 => taglib uriAhttp366www.javatpoint.com6jspA pre#i!AmytagA >?
=mytag3currentate?
Exception +andling in JSP: The !ception is normally an ,bject that is thrown at runtime. It
is the process o# handling the +untime rrors. There may occur !ception any time in your web
application. So handling e!ceptions is a sa#er side #or the web developer. In Jsp$ < ways3
K. (y errorPage and isErrorPage attributes o# page directive
In this case$ you must de#ine and create a page to handle the !ceptions. "s in the error.jsp page. The
pages where may occur !ception$ de#ine the error)age$ as in the process.jsp page.
There are O #iles3
index'&sp #or input values.
=#orm actionPprocess.jspP? *oK3=input typePte!tP namePnKP 6?=br6?=br6? *oK3=input typePte!tP namePn<P 6?=br6?=br6?=input typePsubmitP valuePdivideP6?=6#orm?
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 8/21
process.jsp #or dividing the < numbers & displaying the result.
=> page error)agePerror.jspP >?=>
String numKre:uest.get)arameter-PnKPB
String num<re:uest.get)arameter-Pn<PB
int aInteger.parseInt-numKBint bInteger.parseInt-num<Bint ca6bBout.print-Pdivision o# numbers is3 PGcB
>?
error'&sp #or handling the e!ception.
=> page isrror)agePtrueP >?=hO?Sorry an e!ception occuredE=6hO?!ception is3 => e!ception >?
<. (y 1error2page3 element in web.!ml #ileThis approach is better. (co1 you no need to speci#y error)age in each jsp page. Speci#ying single entry
in th web.!ml will handle the e!ception. In this case$ either speci#ies e!ception;type or error;code with
the location element. I# you want to handle all the !ception$ you will have to speci#y the
java.lang.!ception in the e!ception type element. There are Q #iles3
/e('xml #ile #or speci#ying the error;page element.
index'&sp #or input values
process'&sp #or dividing the < numbers & displaying the result.
error'&sp #or displaying the e!ception.
JSP Action ags: use to per#orm some speci#ic tasks.
"ction tags are used to control the #low between pages and to use Java (ean.
JSP Action ags Description
jsp3#orward #orwards the re:uest & response to another resource.
jsp3include include another resource.
jsp3use(ean creates or locates bean object.
jsp3set)roperty sets the value o# property in bean object.
jsp3get)roperty prints the value o# property o# the bean.
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 9/21
jsp3plugin embeds other components such as applet.
jsp3param sets the parameter value. It is used in #orward & include mostly.
jsp3#allback can be used to print the message i# plugin is working. It is used in jsp3plugin.
The jsp3use(ean$ jsp3set)roperty and jsp3get)roperty are used #or bean development.
&sp:for-ard action tag: used to #orward the re:uest to another resource-jsp$html etc.
Syn3 =jsp3#orward pagePrelative5+% R => e!pression >?P ?66without parameter
=jsp3#orward pagePrelative5+% R => e!pression >?P ?66with parameter
=jsp3param namePparameternameP valuePparametervalue R =>e!pression>?P
=6jsp3#orward?
&sp:incl%de action tag: used to include the content o# another resource-jsp$html or Servlet.
This includes the resource at re:uest time so it is (etter for dynamic pages (co1 there might be changes
in #uture. It can be used to include static as well as dynamic web pages.
Advantage: code +eusability
JSP incl%de directive JSP incl%de action
Includes resource at translation time. Includes resource at re:uest time.
(etter #or static pages. (etter #or dynamic pages.
Includes the original content in 2enerated Servlet. Calls the include method.
Syn3 =jsp3include pagePrelative5+% R => e!pression >?P ?66without parameter
Java 4ean: ItDs a Java class that should #ollow #ollowing conventions3
It should have a no;arg constructor.
It should be Seriali1able.
5se: "ccording to Java white paper$ it is a reusable so#tware component. " bean encapsulates many
objects into one object$ so we can access this object #rom multiple places. It provides easy maintenance.
To "ccess java bean class$ we should use getter & setter methods.
There are < ways to provide the values to the object$ by constructor & setter method.
&sp:%se4ean action tag: used to locate or instantiate a bean class. I# bean object o# bean class is
already created$ it doesnDt create the bean depending on the scope. (ut i# object o# bean is not created$ it
instantiates the bean.
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 10/21
Syn3 =jsp3use(ean id Pinstance*ameP scope Ppage R re:uest R session R applicationP
class Ppackage*ame.class*ameP type Ppackage*ame.class*ameP (ean6amePpackage*ame.class*ame R => e!pression ?P ?=6jsp3use(ean?
Attri(%tes 7 %sage:
id: used to identi#y the bean in the speci#ied scope.
scope: represents the scope o# the bean. It may page$ re:uest$ session or application. e#ault is
page.
page: speci#ies that you can use this bean within the JS) page.
re$%est: can use this bean #rom any JS) page that processes the same re:uest. It has wider scope
than page.
session: can use this bean #rom any JS) page in the same session whether processes the same
re:uest or not. It has wider scope than re:uest.
application: can use this bean #rom any JS) page in the same application. It has wider scope
than session.
class: instantiates the speci#ied bean class -i.e. creates an object o# the bean class but it must have no;arg
or no constructor and must not be abstract.
type: provides the bean a data type i# the bean already e!ists in the scope. It is mainly used with class or
bean*ame attribute. I# you use it without class or bean*ame$ no bean is instantiated.
(ean6ame: instantiates the bean using the java.beans.(eans.instantiate- method.
&sp:setProperty 7 &sp:getProperty: used #or developing web application with Java (ean. In web
development$ bean class is mostly used (co1 it is a reusable so#tware component that represents data.
&sp:setProperty action tag sets a property value or values in a bean using the setter method.
Syn3 =jsp3set)roperty namePinstance,#(eanP property P8P R propertyPproperty*ameP paramPparameter*ameP R propertyPproperty*ameP valuePL string R => e!pression >?NP 6?
!3 =jsp3set)roperty namePbeanP propertyP8P 6? 66incoming re:uest in the bean=jsp3set)roperty namePbeanP propertyPusernameP 6? 66incoming speci#ic prop.=jsp3set)roperty namePbeanP propertyPusernameP valuePumarP 6?66with val
&sp:getProperty action tag returns the value o# the property.
Syn3 =jsp3get)roperty namePinstance,#(eanP property @ property*ameP 6?!3 =jsp3get)roperty namePobjP propertyPnameP 6?
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 11/21
Ex' of 4ean Development in JSP:
inde!.html #or input o# values.
welcome.jsp #ile that sets the incoming values to the bean object & prints the one value.
5ser.java bean class that have setter & getter methods.
Displaying applet in JSP)&sp:pl%gin action tag*: used to embed applet in the jsp #ile. This action tag
downloads plugin at client side to e!ecute an applet or bean.
Syn3 1&sp:pl%gin type Papplet R beanP code Pname,#Class0ileP codebase Pdirectory*ame,#Class0ileP 10&sp:pl%gin3
Expression Lang%age)EL* in JSP: It Simpli#ies the accessibility o# data stored in the Java (ean
component$ and other objects like re:uest$ session$ application.
There are many implicit objects$ operators and reserve words in %.
It is added in JS) version <..
Syn3 UL e!pression N
!mplicit .(&ects:
.(&ects 5sage
pageScope it maps the given attribute name with the value set in the pageScope.
re:uestScope it maps the given attribute name with the value set in the re:uestScope.
sessionScope it maps the given attribute name with the value set in the sessionScope.
applicationScope it maps the given attribute name with the value set in the applicationScope.
param it maps the re:uest parameter to the single value.
param4alues it maps the re:uest parameter to an array o# values.
header it maps the re:uest header name to the single value.
header4alues it maps the re:uest header name to an array o# values.
cookie it maps the given cookie name to the cookie value.
init)aram it maps the initiali1ation parameter.
pageConte!t it provides access to many objects re:uest$ session etc.
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 12/21
Precedence .perators in EL:
VW .
-
;-unary not E empty
8 6 div > mod
G ; -binary
= = ? ? lt le gt ge
E e: ne
&& and
RR or
X3
#eserve -ords:
lt le gt ge e: ne true #alse and or not
instanceo# div mod empty null
M8C in JSP
Stands #or odel$ 4iew and Controller. It is a Design Pattern that separates the (usiness logic$
presentation logic and data.
Model represents state o# application i.e. data. It can be (usiness %ogic.
8ie- represents presentation i.e. 5I-5ser Inter#ace.
Controller acts as an Inter#ace between 4iew and odel. Controller intercepts all the incoming re:uests.
Advantage:
*avigation Control is centrali1ed
asy to maintain the large application
ostly we will use Java (ean class as a odel$ jsp as a view component and Servlet as a Controller.
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 13/21
JSL: represents a set o# tags to simpli#y the JS) development.
Advantages:
Fast Development It provides many tags that simpli#y the JS).
Code #e%sa(ility 'e can use the JST% tags in various pages.
6o need to %se scriptlet tag It avoids the use o# scriptlet tag.
It mainly provides types o# tags3 core tags provide variable support$ 5+% management$ #low control etc.
url3 http366java.sun.com6jsp6jstl6core . pre#i! is c.
s:l tags provide SY% Support
url3 http366java.sun.com6jsp6jstl6s:l. pre#i! is s:l.
!ml tags provide #low control$ trans#ormation etc.
url3 http366java.sun.com6jsp6jstl6!ml. pre#i! is !.
internali1ation tags provide support #or message #ormatting$ number and date #ormatting etc.
url3 http366java.sun.com6jsp6jstl6#mt. pre#i! is #mt.
#unctions tags provide support #or string manipulation and string length.
url3 http366java.sun.com6jsp6jstl6#unctions. pre#i! is #n.
0or creating JST% application$ you need to load jstl.jar #ile.
JSL Core ags:
miscellaneous tags3 catch and out.
url management tags3 import$ url and redirect.
variable support tags3 remove and set.
0low control tags3 #orach$ #orTokens$ i# and choose.
Syn3 => taglib uriAhttp366java.sun.com6jsp6jstl6coreA pre#i!AcA>?
c:catch "lternative approach o# 2lobal !ception Handling o# JS). It handles e!ception & doesnDt
propagate the e!ception or error page. The e!ception object thrown at runtime is stored in a variable var.
=> taglib uriAhttp366java.sun.com6jsp6jstl6coreA pre#i!AcA>?
=c3catch? int iK6B =6c3catch?
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 14/21
c:o%t like Jsp e!pression tag but it is used #or e!pression. It renders data to the page.
c:import like Jsp include but it can include the content o# any resource either within server or outside the
server.
c:forEach It repeats the *ested (ody content #or #i!ed number times or over Collection.
c:if It tests the Condition.
c:redirect redirects the re:uest to the given url.
C%stom ags in JSP: These are user;de#ined Tags. They eliminate the possibility o#
scriptlet tag and separate the business logic #rom the JS) page. The same business logic can be
used many times by the use o# custom tag.
Advantages:
Eliminates the need of scriptlet tag This tags eliminates the need o# scriptlet tag which is considered
bad programming approach in JS).
Separation of (%siness logic from JSP This tags separate the the business logic #rom the JS) page so
that it may be easy to maintain.
#e2%sa(ility This tags makes the possibility to reuse the same business logic again and again.
Ex: prefix:tagname attrKvalueK....attrnvaluen 3
body code10prefix:tagname3
JSP C%stom ag AP! The java!.servlet.jsp.tage!t package contains classes and inter#aces #or JS)
custom tag ")I. The JspTag is the root inter#ace in the Custom Tag hierarchy.
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 15/21
Jspag interface is the root inter#ace #or all the inter#aces and classes used in custom tag. It is a
marker inter#ace.
ag interface is the sub inter#ace o# JspTag inter#ace. It provides methods to per#orm action at the start
and end o# the tag.
Fields:
p%(lic static int E8AL,4.D9,!6CL5DE it evaluates the body content.
p%(lic static int E8AL,PAE it evaluates the JS) page content a#ter the custom tag.
p%(lic static int S;!P,4.D9 it skips the body content o# the tag.
p%(lic static int S;!P,PAE it skips the JS) page content a#ter the custom tag.
Methods:
p%(lic void setPageContext)PageContext pc* it sets the given )ageConte!t object.
p%(lic void setParent)ag t* it sets the parent o# the tag handler.
p%(lic ag getParent)* it returns the parent tag handler object.
p%(lic int doStartag)*thro-s JspException
p%(lic int doEndag)*thro-s JspException
p%(lic void release)* it is invoked by the JS) page implementation object to release the state.
!terationag interface is the sub inter#ace o# the Tag inter#ace. It provides an additional method toreevaluate the body.
p%(lic static int E8AL,4.D9,AA!6 it reevaluates the body content.
p%(lic int doAfter4ody)*thro-s JspException
agS%pport class implements the IterationTag inter#ace. It acts as the base class #or new Tag
Handlers. It provides some additional methods also.
Ex: To create a Custom Tag$ we are per#orming action at start o# the tag.
? Create the ag +andler class and per#orm action at the start or at the end o# the tag.
To create this class$ we need to inherit the agS%pport class & overriding its method doStartTag-. To
write data #or the jsp$ we need to use Jsp/riter class.
The PageContext class provides get.%t)* method that returns the instance o# Jsp'riter class. TagSupport
class provides instance o# pageConte!t byde#ault.
8/18/2019 JSP Word Document
http://slidepdf.com/reader/full/jsp-word-document 16/21
3 Create the ag Li(rary Descriptor)LD* #ile and de#ine tags. It contains in#o o# tag & Tag Handler
class. It must be contained inside the '(;I*0 dir.
3 Create the JSP file that %ses the C%stom tag defined in the LD file'
It uses tagli( directive to use the tags de#ined in the tld #ile.
Attri(%tes:
There can be de#ined too many attributes #or any custom tag. To de#ine the attribute$ you need to per#orm
two tasks3
e#ine the property in the TagHandler class with the attribute name and de#ine the setter method
de#ine the attribute element inside the tag element in the T% #ile
1m:c%(e number PQP310m:c%(e3
m is pre#i!$ c%(e is tag name and n%m(er is attribute.
!teration %sing JSP C%stom tag:
'e can iterate the body content o# any tag using the doAfter4ody)* method o# !terationag inter#ace.
Here we are going to use the agS%pport class which implements the IterationTag inter#ace. 0or iterating
the body content$ we need to use the E8AL,4.D9,AA!6 constant in the do"#ter(ody- method.
C%stom 5#! in JSP C%stom tag: 'e can use the custom 5+I$ to tell the web container about the
tld #ile. In such case$ we need to de#ine the taglib element in the web.!ml. The web container gets the
in#ormation about the tld #ile #rom the web.!ml #ile #or the speci#ied 5+I.
#egistration Form in JSP: 0or creating registration #orm$ you must have a table in the database.
Zou can write the database logic in JS) #ile$ but separating it #rom the JS) page is better approach. Here$
we are going to use ",$ 0actory ethod$ T, and Singletion design patterns. There are many #iles3
index'&sp< #or getting the values #rom user
5ser'&ava< a bean class that having properties and setter and getter methods.
process'&sp< that processes the re:uest and calls the methods.
Provider'&ava< an inter#ace that contains many constants like +I4+/C%"SS$ C,**CTI,*/5+%$
5S+*" and )"SS',+
ConnectionProvider'&ava $ a class that returns an object o# Connection. It uses the Singleton and #actory
method design pattern.
#egisterDao'&ava$ a ", class that is responsible to get access to the database