8/12/2019 As400 Server
1/26
application to run. Do this
by clicking the mouse pointer on the option. If you select the Database query
option, the Query Recall window appears as shown in Figure 1! on page ""#.
De$eloping %&'#(( )a$a &er$lets
""*
Figure 1!. Query Recall +indow
he Query Recall window allows you to recall a pre$ious query or build a new
query. o build a new query, highlight new query, and click on the -pen button.
his displays the Query uilder window, as shown in Figure 1/.
Figure 1/. Query uilder +indow
""#
uilding %&'#(( Internet0ased %pplications with )a$a
he Query uilder &creen allows you to enter an &Q statement and run it on the
%&'#(( system. For e2ample, to retrie$e all rows from the 3arts table in the apilib
library, enter4
select 5 from from apilib.parts
6licking on the Query button causes the &Q statement to run on the %&'#((
system. he results appear in a table as shown in Figure 17.
Figure 17. Query Results
Rather than writing an &Q statement, click on the +i8ard button and allow the
Query +i8ard to help you build the &Q statement that you want to run. he
Query +i8ard prompts you for the name of the table that you want to use. 6lick on
the rowse button to display the a$ailable tables or enter the name of the table,
as shown in Figure 1 on page ""!.
De$eloping %&'#(( )a$a &er$lets
8/12/2019 As400 Server
2/26
""9
Figure 1. Query +i8ard able 3rompt
%fter a table name is entered, click on the :e2t button. he &elect Fields prompt
window appears as shown in Figure "((.
Figure "((. &elect Fields 3rompt +indow
""!
uilding %&'#(( Internet0ased %pplications with )a$a
he &elect Fields window allows you to select which fields you want to include in
the query. o select a field, highlight it and click on the %dd button. In this
e2ample, we select the 3%R:-, 3%RQ;, and 3%R3R fields. %fter selecting
the fields you require, click on the :e2t button to display the &elect 6onditions
window shown in Figure "(1.
Figure "(1. &elect 6onditions 3rompt +indow
he &elect 6onditions prompt allows you to add conditions to the &Q statement.
For e2ample, to select only those records that ha$e a 3%RQ; $alue of greater
than 9(, perform the following steps4
1.
8/12/2019 As400 Server
3/26
he &elect -rder screen allows you to add ordering information to the &Q
statement. For e2ample, to order the records based on the 3%RQ; field in
ascending order, perform these steps4
1.
8/12/2019 As400 Server
4/26
uilding %&'#(( Internet0ased %pplications with )a$a
Figure "(!. -utput Queues Display
6lick on an output queue to $iew the print @obs in that particular output queue as
shown in Figure "(/.
Figure "(/. 3rint )obs y -utput Queue
he 3rint )obs window allows you to select a @ob and hold it, release it, or delete
it from the output queue.
he Files option on the %pplication menu allows you to list the directories in the
%&'#(( integrated file system. Figure "(7 on page "*" shows a directory listing
for the root of the %&'#(( integrated file system.
De$eloping %&'#(( )a$a &er$lets
"*1
Figure "(7. %&'#(( Integrated File &ystem Directories
&elect and click on one of the directories listed to $iew the files stored in that
directory. 6lick on the apptest directory to $iew the contents of that directory as
shown in Figure "(.
Figure "(. Directory isting
&electing &ystem 3erformance from the application menu retrie$es and displays
%&'#(( system performance information as shown in Figure "1( on page "**.
"*"
uilding %&'#(( Internet0ased %pplications with )a$a
Figure "1(. %&'#(( 3erformance Information
he 6ommand line option allows you to enter an %&'#(( command as shown in
Figure "11.
8/12/2019 As400 Server
5/26
Figure "11. %&'#(( 6ommand
If you enter a $alid %&'#(( command, for e2ample4
wrksyssts
he command runs on the %&'#(( system, and the command output is written to
an %&'#(( print file. ;ou are notified that a print file is created as shown in Figure
"1" on page "*#.
De$eloping %&'#(( )a$a &er$lets
"**
Figure "1". %&'#(( 6ommand -utput
he 6hange password option allows you to change your password on the %&'#((
system. &electing this options displays the screen shown in Figure "1*.
Figure "1*. 6hange 3assword
he final option is the &ign off option. &electing it signs you on the %&'#((
system and displays the initial sign on menu.
/." %pplication 3rograms
his section co$ers the )a$a programs that support this application. his
application consists of a number of )a$a classes. hey are supporting class,
ser$lets, and applets. +e co$er some of the key classes here to gi$e you an
understanding of how the application works. he entire application is a$ailable for
you to download from our +eb site.
"*#
uilding %&'#(( Internet0ased %pplications with )a$a
:ote
If you load the ser$lets that make up this application into the Cisual%ge for )a$a
".( Integrated De$elopment en$ironment, some of the classes are marked with
8/12/2019 As400 Server
6/26
a warning message. If you read the warning messages, they indicate that the
get3arameter method is deprecated.
8/12/2019 As400 Server
7/26
data from the
8/12/2019 As400 Server
8/26
&tring userId J req.get3arameter=user=E
&tring urlase J url&tr.substring(, url&tr.lastInde2-f='=E K 1E
&tring cmd J req.get3arameter=cmd=E
if cmd.equalsIgnore6ase=menu=EE H
genBenuout, urlase, sys:ame, userIdE
M else
if cmd.equalsIgnore6ase=signoff=EE H
sign-ffreq, resE
M else H
genInfoout, imgase, sys:ame, userIdE
M
M
out.closeE
M
Figure "1#. &ign-n doGet Bethod
o help you understand the processing that takes place, we added logging to the
&ign-n class. he log for the sign on processing shows the following entries.
&ignon4 &ignon4 doGet4 ?ntered.
he first time the doGet method is called, no parameters are passed in. It calls
the gen&ignonForm method to generate and display the &ign on menu.
&ignon4 &ignon4 gen&ignonForm4 ?ntered.
he gen&ignonForm method shown in Figure "19, builds the &ign on menu
using
8/12/2019 As400 Server
9/26
uilding %&'#(( Internet0ased %pplications with )a$a
pri$ate $oid gen&ignonForm&er$let-utput&tream out, &tring urlaseE
throws I-?2ception
H
log=&ignon4 gen&ignonForm4 ?ntered.=E
log=&ignon4 gen&ignonForm4 imgase J = K imgaseE
&tring host J get = K host K = %&'#(( &ignon N'I?>N'
8/12/2019 As400 Server
10/26
out.println=NR>=E
out.println=ND>Aser ID4N'D>=E
out.println=ND>NI:3A ;3?JO=te2tO= :%B?JO=userO= B%?:GN'D>=E
out.println=N'R>=E
out.println=NR>=E
out.println=ND>3assword4N'D>=E
out.println=ND>NI:3A ;3?JO=passwordO= :%B?JO=pwO= B%?:GN'D>=E
out.println=N'R>=E
out.println=NR>=E
out.println=ND>%&'#(( &ystem4N'D>=E
out.println=ND>NI:3A ;3?JO=te2tO= :%B?JO=systemO= B%?:GN'D>=E
out.println=N'R>=E
out.println=N'%?>=E
'' output submit button
out.println=N3 %IG:J6enter>=E
out.println=NI:3A ;3?Jsubmit C%A?JO=&ignonO=>=E
out.println=N'F-RB>=E
out.println=N'center>=E
out.println=N'-D;>N'=E
M
Figure "19. &ign-n gen&ignonForm Bethod
he urlase $ariable, contains the name of the program to run. his causes the
&ign on menu shown in Figure 1# on page """ to be displayed. he
8/12/2019 As400 Server
11/26
"*7.
De$eloping %&'#(( )a$a &er$lets
"*/
NN -6%N'
8/12/2019 As400 Server
12/26
N'R>
NR>
ND>%&'#(( &ystem4N'D>
ND>NI:3A ;3?J=te2t= :%B?J=system= B%?:GN'D>
N'R>
N'%?>
N3 %IG:J6enter>
NI:3A ;3?Jsubmit C%A?J=&ignon=>
N'F-RB>
N'center>
N'-D;>N'
Figure "1!. Generated &ign -n
8/12/2019 As400 Server
13/26
uilding %&'#(( Internet0ased %pplications with )a$a
public $oid do3ost %&'#(( N'I?>N'
8/12/2019 As400 Server
14/26
out.println=Np>= K e.getBessageEE
out.println=N'-D;>=E
e.print&tackraceE
M
'' then write the data of the response
out.closeE
M
Figure "1/. &ign-n do3ost Bethod
&ignon4 urlase J http4''localhost'ser$let'
&ignon4 &ignon4 genBain4 ?ntered.
%fter a successful sign on, the genBain method displays the main application
menu and the information menu shown in Figure 19 on page ""*.
De$eloping %&'#(( )a$a &er$lets
"*
pri$ate $oid genBain&er$let-utput&tream out, &tring urlase, &tring sys:ame, &tring userIdE
throws I-?2ception
H
log=&ignon4 genBain4 ?ntered.=E
out.println=Nhtml>=E
out.println=Nhead>=E
out.println=Ntitle>%&'#((N'title>=E
out.println=N'head>=E
out.println=Nframeset colsJ"9P,5>=E
out.print=Nframe srcJ=E
8/12/2019 As400 Server
15/26
8/12/2019 As400 Server
16/26
Database queryN'%>N'li>
Nli>N% Banage print @obs by userN'%>N'li>
Nli>N% Banage print @obs by output queueN'%>N'li>
Nli>N% N'li>
Nli>N% &ystem
performanceN'%>N'li>
Nli>N% 6ommand lineN'%>N'li>
Nli>N% 6hange passwordN'li>
Nli>N% &ign
offN'%>N'li>
N'ul>
Nhr widthJ=1((P=>
N'-D;>
Figure "1. %pplication Benu
8/12/2019 As400 Server
17/26
he
8/12/2019 As400 Server
18/26
:ow that you understand how the ser$lets are in$oked, you can look at how they
work. he application ser$lets are similar. his section looks at a fairly simple
ser$let, which calls a program on the %&'#(( system and a more comple2
application which allows &Q query statements to be created and e2ecuted on
the %&'#(( system. y understanding how these applications work, you can look
at the code and understand how the other applications work.
/.*.1 &ystem 3erformance &er$let
his section looks at the &ystem performance ser$let. his ser$let uses the
%&'#(( oolbo2 for )a$a distributed program call D36E class to call a program on
the %&'#(( system, which returns system performance information. he
information returned by the %&'#(( program is displayed in the browser by
imbedding it in an
8/12/2019 As400 Server
19/26
if sys:ame.equalsIgnore6ase=localhost=EE
H
&tring earl J N'
8/12/2019 As400 Server
20/26
"#"
uilding %&'#(( Internet0ased %pplications with )a$a
6licking on the &ystem 3erformance option in$okes the doGet method of the
3erfBon class, which is shown in Figure ""1 on page "#", of the 3erfBon ser$let.
his method builds the
8/12/2019 As400 Server
21/26
Db&elect&er$letX&er$let
&Q-rderX%pplet
&Q+hereX%pplet
&Q+i8ardX%pplet
+hen you click on the Database query option from the application menu, the
doGet method of the Db&elect&er$let class is called with a parameter of qrylist.
Refer to Figure "1 on page "#(, to see the
8/12/2019 As400 Server
22/26
Ninput typeJhidden nameJuser $alueJauser>
Ninput typeJhidden nameJkey $alueJas#((abcauser(7#/#"1">
Nbr>
Ncenter>
N&??6 :%B?J=query= &IY?J9>
N-3I-: C%A?Jnew selected>Znew query[
N'&??6>
Nbr>Nbr>
Ninput typeJsubmit nameJopen $alueJ-pen>
Ninput typeJsubmit nameJdelete $alueJDelete>
N'center>
N'-D;>
Figure ""*.
8/12/2019 As400 Server
23/26
he qry3rompt method builds and displays the Query &tatement N'I?>N'
8/12/2019 As400 Server
24/26
Ninput typeJradio nameJqtype $alueJ=&C=>ab separated $ariable &CE format
Nbr>Nbr>
Ninput typeJsubmit $alueJQuery>
Ninput typeJsubmit nameJsa$e $alueJ&a$e...>
N'center>
N'form>
Np>?nter the &Q statement.
For e2ample, \select 5 from apilib.parts\
to use the demo database.
Np>If you would like some assistance, you can use the
wi8ard button to get some help on formulating your query.
&Q gurus can simply type in the query and use the query button.
N'body>
Figure ""9.
8/12/2019 As400 Server
25/26
nameJcmd, $alueJquery
nameJsystem, $alueJas#((abc
nameJuser, $alueJauser
nameJkey, $alueJas#((abcauser(7#/#"1"
radio nameJqtype, defaultJhtml
nameJwi8ard, $alueJ+i8ard
nameJsa$e, $alueJ&a$e...
uilding %&'#(( Internet0ased %pplications with )a$a
Figure ""!. Query &tatement +indow
/.*.".1 +riting your -wn &Q &tatements
%t this point in the Database Query application, you can enter your own &Q
statements or use the +i8ard to help you build an &Q statement. o see how the
+i8ard works, refer to &ection /.*.".", ]Asing the +i8ard^ on page "#7. In this
section, write our own &Q statement4
select 5 from apilib.parts
6licking on the Query button runs the do3ost method. If a cmd $alue of query is
recei$ed in the do3ost method, the performQuery method is called. he
performQuery method sees how we want the results returned by checking which
radio button is selected. In this case, the Ciew results in
8/12/2019 As400 Server
26/26
6reates a statement ob@ect using the create&tatement method
?2ecute the &Q statement we entered using the statement ob@ect
Formats the rows into a table using
Top Related