You are on page 1of 8

Advanced Java Programming (22517)

of Generic
the use
demonstrate
actical No. 21: Write a program to
servlet
Servlet as a paramneterized

. Practical Significance: server or application


web
the Java programs that run on the Java-cnabled the
t s are obtained from
the wcD seTVeT, process
uscd to handic the requcst the web server
Tver.
They are
response
back to

uest, produce the responsc, and then send

I. Relevant Program Outcomes (POs) sCiences and basic


mathcmatics,
knowlcdee of basic
BASIC knowledge: Apply problems.
Cngineering to solve the computer group rclated knowlcdge to solve the
Discipline knowledge: ApplyComputer Programming
computer group related problems. practices to use the
experiments and
and practice: Plan to perform
Aperiments
results to solve the computer group relatcd problem5. and
programming/ technologies
tools: Apply rclevant Computer
Engincering
tools with an understanding of the limitations. team member in
a leader and
Function cffectively as
ndividual and Team work:
diverse/multidisciplinary teams.
written form.
Communication: Communicate effectively in oral and

III. Competency and Practical skills


To develop Dynamic web Application
skills:
Thepractical is expected to develop the following
1. Able to apply the servlet for dynamic web application.
from client.
2. Able to demonstrate the use of servlet for parameter received

Iv. Relevant Course Outcome(s)


Develop programs using Servlet

V. Practical Outcome (PrOs)


Write a program to demonstrate the
use of HttpServlet as a parameterized servlet

VI. Relevant Affective domain related Outcome(s)


1. Follow precautionary measures.
2. Follow naming conventions.
3. Follow ethical practices.

VII. Minimum Theoretical Background


Servlets are the Java programs that run on the Java-enabled web server or application
server. They are used to handle the request obtained from the web server, process the
request, produce the response, and then send response back to the web server.

The Servlet Container


Servlet container, also known as Servlet engine is an integrated set of objects that
provide run time environment for Java Servlet components.
in simple words, it is a system that manages Java Servlet components on top of the
Web server to handle the Web client requests.
The ServletRequest class includes methods that allow you to read the names and

state Board of
Technical Education 116
Maharashtra
Advanced Java Programming
(22517)

XI. Result (Output of Code):


******************** ****** *********** ****. *

***'****
*********'****** *****

*************.
***** ****
*****'* ****

****'****

XII. Practical Related Questions


Nole: Below given are few sample questions for reference. Teacher must design
ore such questions so as to ensure the achievement of identified Co.
1. List the
types and uses of Servlet
2. List the
3.
advantages of Servlet over CGI?
Draw the servlet life
cycle?
4 What is servlet container?

(Space for answer)

ses..af...SVst.
...A)...S.S.e.d..a...reate..
**

eh..ppli.catian.
..aMid.e...my.ntsxEac.e. .l.acc.es...n.cl.udi.
.c.wm.eMtrdion..
****

************* *°°°**°°**.
*****************

rle procide...8.etter..pex.k.or.mauRAtHad.cnL
.. eI..0...Xoceng.ing.. m.e..0M..1mOTyUrili.z.atrion
*****

.b.e.c.au.....le...uses.enesi.t...a....lti.hrrsdi r .
***************
***°**°°**°*°*

****"
***

***°*°**
**°******.

..S...ormpan£ud. .LDeb..bratt-tt..Sexe
***

.h..ntevact...ith..awa..S.enCvle:
****"***

**********.****.

**************
*************

**J*********** ***

**°°*************°*****
***** ***

**'°°*****

*******°***°***°.

*******

**********************''**** ****.***.

*********°******
****°******
*******************

*****

*********
* * * * * * * * * *

***********
**********
*****"

Maharashtra state B0ard ot l echnical Education


120
************** *
'***** ************** **....
******* ** ******
****
******
***

****

* ***** ******

***** ************* *********


****
...

***
******'*****
****

**** ****
. ***************************** **

**************
NII. Exercise

. Develop servlet program to print


2. Develop a program to receive theHello MSBTE in browser window.
received parameter to browser. parameter through HTML forms and send back
(Space for Answer)
*******.***.

imeat. MA..o.y.c.ep.tion.
mp.. AX..rvle..M.l.et.ej.cep.t.O.
.ap.s.xA.
.m.pa. AIC)...A te eepian.,S.rx.l.et.r.eaue
...po. M.K..exvlet.Http9ex.vxl.et.&.esR.on.ce
ul.i.c..as..Rel!.aM9.8T.E.. ca1d..HIPe.8eTver
****** ..

..Xat.eLt£d...M6id.daa.e.H.Ipcexu.e.enuec.
**********
...MTIRs.cxule....Respom.c.e....h.ratw!a..
**********2******* .O.SXc.e..i.co...
* * * * * * * .

QYS..eM...A.uà....xcixnt.l.n.....e..a..MS.8T.E.

*********

R..Dte.cted....ai.o..do.oat.(.H.TA.p.a.AL.Mle.t...equcH

...TI.RS.exu.let.R.e.C.p.0.me.e....hxaLa....

***** ***.
...AACep.t.ia.
**** *******.

********

**** **

***

121

Maharashtra state
ra state Board of
Technical
Educaion
Java Programming (22517)

Practical No. 22: Write


Servlet program to send username
a
an
password using HTML forms and
user.
authenticate tne

Practical Significance:
There is a possibil of
smtpservlet
developing 'n' types ofservlet
etc. for all these protocol specific servlets. like GenerrcServier
classes hrtpservier. pser.
s e
common super r class containing common properties and logu S0. G e n e n c > e r v t T s
not a separate type of servlet.
As of now Servlet API 1s giving only one subclass to GenericServier t.e
Hp>eT
lass because all web serverS are designed based on the
protocol http
Il.
Relevant Program Outcomes (POs)
.Basic knowledge: Apply knowledge of basic mathematics. sciences nt s e
engineering to solve the computer group related problems
Discipline knowledge: Apply Computer Programming knowiedge to solve me
computer group related problems
Experiments and practice: Plan to pertorm experiments and practces tw use the
results to solve the computer group related problems.
tools: Apply relevant Computer programming tecihmoiogies n c
Engineering
tools with an understanding of the limitations.
Individual and Team work: Function effectively as a leader and reum memcer a
diverse/multidisciplinary teams.
Communication: Communicate ettectively in oral and wrimen to

lIl. Competency and Practical skills


To develop Dynamie web Application
The practical is expected to develop the fotlowing skils:
. Able to apply the servlet program for dynamic web applicanion.
2. Able to demonstrate the use of serviet for parameter receved trom cient.

N, Relevant Course Outcome(s)


Develop programs using Servlet.
Practical Outcome (PrOs)
Write a program to demonstrate the us of HrtpServlet as a parameterzei serv iet

Relevant Affective domain related Outcome(s)


I. Follow precautionary measurrs
2. Follow naming conventions
3. Follow ethical practices.

VIL Minimum Theoretical Background


- it is prococoi indenemipme
Generic servlets extend javax.servlet.GenericServlet
trum which
serviet all oher Serv lens
Servlet is a base class
m
Servlet. Generie HTTP. FEP and SMTP protueols. lt imr
erived. Generie Servlet supports tor
intertace. it has Only initi AT de
)
meth
the Servlet and ServletConfig
lt alsv implements he og mecho
ntertace in its lite cycle.
ServletConfig
ServletContext intertace.
anarashtra
Sa state
t e BOr
Board of Tachnical Educanou
(22517)
anced Java Programming

import javax.servlet.http.HtpServletResponse:
nublic class AthonticationServlet extends HttpServlet

protected void doPost(HttpServletRequest request, HttpServletResponse


response) throws
ServletException. IOException
response.setContentType("text html.charset-UTF-8"):
PrintWriter out response.getWriter().
String pass "abhishek12345"
String username.password:
username=request.getParameter("username"):
passwordrequest.getParameter("password").
if(username.equals(uname) && password.equals(pass)

out.println("Login Successfull"):

else

out.println("Login Unsuccessfull"):

(Space for Answer)

ava.io *
mport
Public cdass Cliet
arqeca)
orgeta)
main (String
Gahic yoid
puhlic
Ty "tocal
hostT
hast
2rinq
i m p o t : 2.1000;

adreez
Inet addrettqetby name (hag+)
Tnetaddvet
(add, part+
6olut
het
Selut 0S 6eckt get OutgBream!
Shream
Oudput 6uf fer writer (ag).
BufFer
=
hriter bu De
Strin number "2"
numb e r +
Qendrmettaqt

S+Yina
25
iduuation
slate oard uf l echiival
Advanced Java Programming (22517

baoH+e (Send message


busFluch
Sughemput. print'n m9 e + server

XI. Result (Output of Code):

n.e ere..M.O.qX.as S.eyecuttd o2emd


.r.4p.oR.od.r.o....ue.ing.. .TML...EsTm.
auth.tsaticat.ta. S....
XII. Practical Related Questions
Note: Below given are few sample questions for reference. Teacher must design
more such questions so as to ensure the achievement of identified Co.
1. List the types ofservlet and default port for there services.
2. List the difference between doGet) and doPost) method of servlet.
3. Explain ServletConfig and ServletContext.
4. Explain ServletinputStream Class and ServletOutputStream Class with methods

(Space for answer)

...A.nn.eri.C..xxle.:
..HIO...er.Mel.et...

.do.ln.et.L. &ad..PCNALTeer.are.pend..o.RL
***

....al.ana...uui...beade.r..infarmatio.n
*********

doFost.C).En..hiS. arametsx.S. e. t..in.


*****

Sep.e.r.autE .n.af...adu
. * * * * * * * * * * * * ***** ******* *********-***********--

***" *****

Board ot Iechnical Education


Maharashtra state
cvvleh
Cont in ia aamett r i pccifted
for
0Yatiaulaw 9evle4ac
nown..o.moter Aervle
,

6exvletInud. GAream)6t.yle. Input.txeam.


alo.cg proxid ela trea
0.eoad
mekhod.
binamy.al.c..Aucha3images..
Ainpuialr.com.C.)..
* * * * * * * * *

*****'**'*****' ****" *****

Sexrlet.0utput.a}r.eam).. L px.oxid.e...9tr.cam.. .*

**

.hinamy..ata. . .

jnto..I.EAADAice.....CaM...bat.x.aet...get.Outputs9.txEOTOT
****** .

***

*****

... . ** .

******

****

***

***

XIII. Exercise
I. Develop servlet program to retrieve data from List and Radio Button using HTML

Forms.
2. Devclop a program to reccive student subject marks through HTML. form
or Failed in Examination...
TextField and send the response as passed
(Space for Answer)
*********

**********

Maharashhtra 1 state Board of Technical Education 127


Advaneed lava Prngranmny(29917)

iop0 * * ******** ***********


************* ***

importJawa 3ervlet *****'***'****' ****************|

pori1 AMC Semvle http6exvlet.... ******************

PLubli C emo0.6erv let tmd. bttp.9.ervle


****
*******************

*****'*****'************* *** * ***********

publie Yoid goGHet (Http.9tv.leE)..tbro..Sevle


exceptiAnI0 AC.eption.. * ************

prinaite.p..xe.3..t.o.riM... *******
******'***.

Se Vlet.Conte...can.cut..q.e serle.t.Co.nkeC);
String d.r.ivex.nam.e..Ont.J.A..t.n.d.p.ox.AMn.etr
*'**''********** ************** *************'*******'****'***********
.dname");
Pwnit.le..dniMeN.NGm.C.... dtive.name
p..lose.C... f'********** ******** * ****'*****
****

.*******.
****'*****'***°' ***'***''**°*'***'.

**********************************************************************

2 weh...m... 1***'*** ********* ******** *****

LA.Lh.App.
**
.Stle amE)...Ge.Lekn.ekw.ark.en.ule..name)
****

.SeM..lek.class.Doma.Sex..ek.x.S.em.v.le..al.a.eo...
**********'***** jPaMaMy. *************************

..paKa.m. me.cnome..p.oca.Ym.a.me)...
******
pNaXD.Uodue..um..jdla.c..ad.bc.jd.lC.odbc.dr.LX.ED
MN)....alLL.e. ********
********************

eyle..map.Rl.na..
*************°.
******************************** **********

Sexx.e. m.e).Stivlet.net.u6xK.6.exx.let..ame
*************** fx...o.. .dtexn...
****'****'****'***
.x.!.e...PP.i...g.). ******************************
**********

********* . *
*** *
****************** ' * ***

******************** *

. '***********'***'*** ********** *** '********'********


*****
**************'****'** **'************** ....
**
******

,. **
**************'************'****'***"**** ********''************ **** .
.. * * * *" * * .

*************'***"*'**'**'**************
. * ************'***********
*******'********'****'****'****' '*'********* * ******

*******'*****'***********'****'************** .

* .........
****************** **************** ******* * *

*****************'****' **
*******'***'
*****************************
* .
***

************** **

**********'************** ************** **
* * ********

Maharashtra state Board of Technical Education


128

You might also like