Tuesday, May 10, 2011

features of servlet context

1 ) Describe purpose and features of servlet context
2- develop servlet context listener to initialize a shared application resource.

--A ServletContext object is runtime representation of web app..

--context object accessible to all servlets in web app

-- getServletContext is used to access context object

-- setAttribute is used to store context-scoped attributes in context object.

-- getAttribute is used to retrieve context-scoped attributes from context object.

-- removeAttribute method used to remove context-scoped attributes.

ex:
- LeagueList attribute used to create shared list of leagues
- context object used to access leagueList attribute.

Mod AddLeagueServlet

-- Retrieves context object.
-- Retrieves leagueList attribute
-- Adds new league to the list.

modifying list leagueservlet

-- Retrieves context object
-- Retrieves leagueList attribute
-- uses leagueList attribute to generate view.


Initializing a context scoped attribute

-- context listener used to initialize shared application resource.

process to init leagueList context-scoped require to perform following

-- Determine location of leagues
-- read
- creat league object for each row and store in list object.
-- store list of leagues in leagueList context
-- Log the fact whether list was initialized or any exception thrown by code.

web app life cycle

life cycle of web application involves following activities

-- all web app initialized when web container started.
-- all web app destroyed when web container shut down.

ServletContextListener Interface

InitializeLeage is context listener used to create stor list of leagues as leagueList attribute
Initialize league implements servletContextlistener which has following methods.

-- contextInitialized method
-- contextDestroyed method.

Determining loc of leagues data file

-- init list of leagues, determin location of leagues date file.
-- leagus date file stored in /web-ifn/data/leagues.txt
-- InitializeLeague code performs following operations for determining location of leagues date file

-- Retreive context object from event argument.
-- Retreive leagues-file context parameter.

Reading Data File and Creating League Objects

-- create input stream to data file, provide read only access to data file.
-- provide buffered reader for input stream.
-- enable data file to be read in while loop.
-- split each row by tab char.
-- construct league obj for each row in data file.
- display league object added to leagueList.

Storing leagues
InitializeLeague code performs following operation
-- store leagueList in context scope
-- record success to log file.

Configuring the listener.

-- configure web.xml dd as follows

-- configure InitializeLeagues listener class
-- leagues.txt file in under /web-inf/data/ directory.

sequence of tasks to init leagueList

-- determine location of leagues.txt file
-- read the leagus.txt file
-- create league object for each row in leagues.txt file and store in list object
-- store list of leagues in leaguList context attribute
-- Log fact that list initialized, or log any exception thrown by this code.

summary:

-- purpose and features of the servlet context.
-- developing servlet context listener to initialize shared application resource.

Wednesday, April 27, 2011

Describe a servlet life cycle

WCD certification- week 4/27

Developing dynamic forms - introduction
1) Describe servlet life cycle
2) customize a servlet with init parameters
3) Explain error reporting within web forms
4) Repopulate the web form