Next Previous Contents

5. Xrhsimopoiwntas tis Java CGI Klaseis

Yparxoyn pros to paron treis kuries klaseis poy yposthrizontai -- CGI, Email kai HTML. Skeftomai na pros8esw klaseis gia na antimetwpisw ta MIME-diamorfwmena eisagomena (input) kai ejagomena (output) -- MIMEin & MIMEout, antistoixa.

Yparxoyn epishs merikes support kai test klaseis. CGI_Test, Email_Test kai HTML_Test skopeuoyn na xrhsimopoih8oun gia na elegjoyn thn egkatastash sas. Mporoun epishs na xrhsimopoih8oun san ena shmeio-ekkinhshs gia ta dika sas programmata Java poy xrhsimopoioun ayth th biblio8hkh klasewn. H Text klash einai h yperklash kai gia tis duo klaseis, thn Email kai thn HTML.

5.1 CGI

Suntajh klashs

public class CGI

Perigrafh klashs

H CGI klash krataei tis ``CGI Plhrofories'' -- Metablhtes periballontos apo ton diakomisth istou kai to onoma/timh poy stelnontai apo mia forma otan h submit energeia einai epilegmenh. Oles oi plhrofories apo8hkeuontai se ena Properties antikeimeno klashs.

Ayth h klash einai sto paketo ``Orbits.net''.

Perilhch melwn

CGI() // Kataskeyasths.

getNames() // Pairnei th lista onomatwn.

getValue() // Pairnei thn timh formas kata prosdiorismeno onoma.

Deite epishs

CGI_Test.

CGI()

Purpose

Kataskeyazei ena antikeimeno poy periexei ta dia8esima CGI dedomena.

Syntax

public CGI()

Description

Otan kataskeyazetai ena antikeimeno CGI, oles oi dia8esimes CGI plhrofories anarrofountai se apo8hkh topika sto neo antikeimeno.

getNames()

Purpose

Kanei lista twn onomatwn poy einai orismenes gia na exoyn antistoixes times.

Syntax

public Enumeration getKeys ()

Description

Parexei thn plhrh lista twn onomatwn gia ta opoia antistoixes times einai orismenes.

Returns

Mia Enumeration olwn twn orismenwn onomatwn.

getValue()

Purpose

Epanakta thn value sysxetismenh me to name poy exei oristei.

Syntax

public String getValue ( String name )

Description

Ayth h me8odos parexei th antistoixia metaju twn names kai values poy stelnontai apo mia HTML forma.

Parametros

name

To kleidi kata to opoio oi times epilegontai.

Returns

Ena String poy perilambanei thn timh.

5.2 CGI_Test

Ayth h klash parexei ena paradeigma toy pws na xrhsimopoieite thn klash CGI kai ena programma elegxoy poy mporei na xrhsimopoih8ei gia na epibebaiwsei oti to paketo Java CGI leitoyrgei swsta.

Perilhch melwn

main() // Programma main().

Deite epishs

CGI.

main()

Purpose

Parexei mia main() me8odo.

Syntax

public static void main( String argv[] )

Description

Ayto einai to shmeio kataxwrhshs gia ena programma CGI poy den kanei tipota allo apo to na anaferei mia lista me ola ta dia8esima onoma/timh zeygaria kai tis trexoyses times toys.

Parametros

argv[]

Epixeirhmata perasmena sto programma apo to java.cgi script. Pros to paron axrhsimopoihth.

5.3 Email

Suntajh Klashs

public class Email extends Text

Perigrafh klashs

Mhnumata sxhmatizontai me thn Text klash add*() me8odoys kai tis e-mail-sygkekrimenes me8odoys poy prosti8entai apo aythn thn klash. Otan oloklhrw8ei, to mhnyma stelnetai ston proorismo toy.

Ayth h klash einai sto paketo ``Orbits.net''.

Perilhch melwn

Email() // Kataskeyasths.

send() // Stelnei to e-mail mhnyma.

sendTo() // Pros8etei enan proorismo gia to mhnyma.

subject() // Ry8mizei to 8ema: gia to mhnyma.

Deite epishs

Email_Test, Text.

Email()

Purpose

Kataskeyazei ena antikeimeno to opoio 8a periexei ena email mhnyma.

Syntax

public Email()

Description

Ry8mizei ena keno mhnyma gia na oloklhrw8ei apo tis Email me8odoys.

See Also

Text.

send()

Purpose

Stelnei to e-mail mhnyma.

Syntax

public void send ()

Description

Ayth diamorfwnei kai stelnei to mhnyma. An kamia dieu8ynsh proorismou den exei ry8mistei, de lambanetai kamia energeia.

sendTo()

Purpose

Pros8etei enan proorismo gia ayto to mhnyma.

Syntax

public String sendTo ( String address )

Description

Pros8etei thn address sth lista proorismwn gia aythn thn me8odo. Den yparxei kanena orio ru8mishs ston ari8mo proorismwn poy ena e-mail mhnyma mporei na exei. Eimai sigoyros pws an sxhmatisete th lista arketa megalh, mporeite na yperbei te to mege8os ths listas parametrwn poy o Mail Transport Agent mporei na apodex8ei h na katanalwsete th mnhmh sas.

Parameter/

address

Enas proorismos gia na steilete ayto to mhnyma.

subject()

Purpose

Stelnei to 8ema gia ayto to mhnyma.

Syntax

public void subject ( String subject )

Description

Ayth h me8odos ry8mizei to keimeno gia thn grammh Subject: toy e-mail. An klh8ei perissoteres apo mia fores, to teleytaio ry8mismeno 8ema einai ayto poy xrhsimopoieitai.

Parameter

subject

To keimeno ths Subject: grammhs aytou toy mhnumatos.

5.4 Email_Test

Ayth h klash parexei ena paradeigma toy pws na xrhsimopoieite thn Email klash kai ena test programma poy mporei na xrhsimopoih8ei gia na epibebaiwsei oti to Java CGI paketo leitoyrgei swsta.

Perilhch melwn

main() // Programma main().

Deite epishs

Email.

main()

Purpose

Parexei mia main() me8odo.

Syntax

public static void main( String argv[] )

Description

Ayto einai to shmeio kataxwrhshs gia ena programma CGI poy anaferei mia lista me ola ta dia8esima onoma/timh zeygaria kai tis trexoyses times toys. Epishs, 8a steilei ayth th lista sthn ka8orismenh dieu8ynsh sthn Email metablhth.

Parametros

argv[]

Epixeirhmata perniountai sto programma apo to java.cgi senario. Pros to paron axrhsimopoihta.

5.5 HTML

Suntajh klashs

public class HTML extends Text

Perigrafh klashs

Mhnumata sxhmatizontai me thn Text klash add*() me8odoys kai tis HTML-sygkekrimenes me8odoys poy prosti8entai apo aythn thn klash. Otan oloklhrw8ei, to mhnyma stelnetai ston proorismo toy.

Pros to paron, den yparxei elegxos sfalmatwn gia na epibebaiwsei oti oi me8odoi dhmioyrgias-listas xrhsimopoiountai se mia swsth seira, opote o programmatisths prepei na pairnei metra gia na mhn parabiasei thn HTML suntajh.

Ayth h klash einai sto paketo ``Orbits.net''.

Perilhch melwn

HTML() // Kataskeyasths.

author() // Ry8mizei to onoma toy syggrafea toy eggrafoy.

definitionList() // 3ekina mia lista orismwn.

definitionListTerm() // Pros8etei enan oro sth lista orismwn.

endList() // Teleiwnei mia lista.

listItem() // Pros8etei mia kataxwrish se mia lista.

send() // Stelnei to HTML mhnyma.

title() // Ry8mizei to keimeno gia ton titlo toy eggrafoy.

Deite epishs

HTML_Test, Text.

HTML()

Purpose

Dhmioyrgei ena antikeimeno poy 8a periexei ena HTML mhnyma.

Syntax

public HTML()

Description

Ry8mizei ena keno mhnyma na symplhrw8ei apo tis HTML me8odoys.

See Also

Text.

author()

Purpose

Ry8mizei to onoma toy syggrafea toy eggrafoy.

Syntax

public void author ( String author )

Description

Ry8mizei to onoma toy syggrafea toy eggrafoy se author.

Parameter/

author

To keimeno poy prepei na xrhsimopoih8ei san o syggrafeas aytou toy mhnumatos.

See Also

title().

definitionList()

Purpose

Arxizei mia lista orismwn.

Syntax

public void definitionList ()

Description

Arxizei mia lista orismwn. H definition list einai mia lista eidikeymenh etsi wste ka8e kataxwrish sth lista einai enas term akoloy8oumenos apo to text orismwn gia ayton ton oro. H arxh mias listas orismwn 8a prepei na akoloy8eitai apo toylaxiston) ena oros/keimeno zeygari kai mia klhsh sthn endList() me8odo. Shmeiwste pws, pros to paron, oi listes den mporoun na einai fwliasmenes (nested) h mia mesa sthn allh.

See Also

definitionListTerm(), endList(), listItem().

definitionListTerm()

Purpose

Pros8etei enan oro sth lista orismwn.

Syntax

public void definitionListTerm ()

Description

Pros8etei enan oro sth lista orismwn. To keimeno gia to kommati toy oroy ths trexoysas kataxwrhshs listas 8a prepei na episynaptetai sto mhnyma afou h me8odos aytou kaleitai kai prin mia antistoixh listItem me8odos kaleitai.

See Also

definitionList(), listItem().

endList()

Purpose

Teleiwnei mia lista.

Syntax

public void endList ()

Description

Teleiwnei mia lista. Ayth h me8odos kleinei mia lista. Shmeiwste oti, pros to paron, oi listes den mporoun na einai fwliasmenes (nested), h mia mesa sthn allh.

See Also

definitionList().

listItem()

Purpose

Pros8etei mia kataxwrhsh se mia lista.

Syntax

public void listItem ()

public void listItem ( String item )

public boolean listItem ( String term, String item )

Description

Pros8etei mia kataxwrhsh se mia lista. An h prwth forma xrhsimopoieitai, to keimeno gia thn trexwn antikeimeno listas 8a prepei na episynaptetai sto mhnyma afou h me8odos ayth kaleitai kai prin alles me8odoi listas kalountai. Sthn deuterh kai trith forma, to item keimeno prosdiorizetai san mia parametros sth me8odo anti na (h epipros8etws sto na) episynaptetai sto mhnyma. H trith forma einai eidikh stis listes orismwn kai parexei kai ton oro kai toy orismo ths kataxwrhshs listas.

Parameters

item

To keimeno ayths ths kataxwrhshs listas.

term

To keimeno ayths ths listas orismwn toy kommatiou toy oroy kataxwrhshs.

See Also

definitionList(), definitionListTerm(), endList().

send()

Purpose

Stelnei to HTML mhnyma.

Syntax

public void send ()

Description

Stelnei to HTML mhnyma.

title()

Purpose

Ry8mizei to keimeno gia ton titlo eggrafoy.

Syntax

public void title ( String title )

Description

Ry8mizei to keimeno gia ton titlo eggrafoy.

Parameter

title

To keimeno aytou toy titloy toy mhnumatos.

See Also

author().

5.6 HTML_Test

Ayth h klash parexei ena paradeigma toy pws na xrhsimopoieite thn HTML klash kai ena test programma poy mporei na xrhsimopoih8ei gia na epibebaiwsei oti to paketo Java CGI leitoyrgei swsta.

Perilhch melwn

main() // Programma main().

Deite epishs

HTML.

main()

Purpose

Parexei mia main() me8odo.

Syntax

public static void main( String argv[] )

Description

Ayto einai to shmeio kataxwrhshs gia ena programma CGI poy epistrefei mia lista twn dia8esimwn onoma/timh zeygariwn se ena HTML eggrafo, me to ka8e onoma/timh zeygari na apeikonizetai se ena stoixeio listas orismwn.

Parametros

argv[]

Epixeirhmata perasmena sto programma apo to java.cgi senario. Pros to paron de xrhsimopoiountai.

5.7 Text

Suntajh klashs

public abstract class Text

Perigrafh klashs

H klash einai h yperklash twn Email kai HTML klasewn. Mhnumata xtizontai me tis me8odoys se aythn thn klash kai symplhrwnetai kai diamorfwnetai me tis me8odoys se ypoklaseis.

Ayth h klash einai sto paketo ``Orbits.text''.

Perilhch melwn

Text() // Kataskeyasths.

add() // Pros8etei keimeno se ayto to antikeimeno.

addLineBreak() // Pros8etei mia diakoph grammhs.

addParagraph() // Pros8etei mia diakoph paragrafoy.

Deite epishs

Email, HTML.

add()

Purpose

Pros8etei keimeno se ayto to antikeimeno.

Syntax

public void add ( char addition )

public void add ( String addition )

public void add ( StringBuffer addition )

Description

Pros8etei addition sta periexomena aytou toy antikeimenoy keimenoy.

Parameter

addition

Keimeno poy prepei na proste8ei sto antikeimeno keimenoy

See Also

addLineBreak(), addParagraph().

addLineBreak()

Purpose

Anagkazei mia diakoph grammhs se ayto to shmeio sto keimeno.

Syntax

public void addLineBreak ()

Description

Pros8etei mia diakoph grammhs sto keimeno sto trexon shmeio.

See Also

add(), addParagraph().

addParagraph()

Purpose

Arxizei mia nea paragrafo.

Syntax

public void add ()

Description

Arxizei mia nea paragrafo se ayto to shmeio sth roh keimenoy.

See Also

add(), addLineBreak().


Next Previous Contents