ns. How to Install Tomeat 7 (on Windows, Mac and Ubunty) and Got Started with Java Seret Programming
How to Install Apache Tomcat 7/8 ser ranterraca
1b aude tomatoe
(on Windows, Mac, Ubuntu) eee tous
and 23 st cong oman
Get Started with Java Servlet 26 Sti? 6 ite Weli-wot
2:7 STEP 7. Wit a Database Serv
Programming 28 (Advance) Deploying Serlt
3, How to Debug?
Ths tutors an be completed in 8 how session
‘Ths instaltion and confguration guide is appkabl to Tomcat 7/8, and posiby the earr versions
Take note that Tomes 8 requires JOK 17. wil NOT work wih JDK 15.
1, Introduction
1.1 Web Appl
ation (Webapp)
Aub application ior webapp), une standalone appeaton runs over the Internet, ample of webapps are goog, amazon ebay, facebook and twtr.
[A.wobapp is typialy a 3-tir (or mut in clint server database application run over the Internet 2s ilstratd in the clagram below. I comprises fe
components
1. HTTP Server: Eg, Apache HTTP Server, Apache Tomeat Server, Mics Intemat Information Server BS}, nginx Google Web Server (GW, and
others.
2. HITP Client (or Web Browser): Eg, Intamet Explorer (MSI, FireFox Chrom, Safar nd others
3, Database: Eg, Open-source MySQL, Apache Darby, mSQl, SQlite, PostgreSQL, OpenOlfice's Bat; Commercial Oracle, BM D2, SAP Sybase, MS SQL
‘Server, MS Acces: and others
4, Client-Side Programs: couls be writen in HIML Form, JavaScript V8Serpt lah, an others
5. Server-Side Programs: could be writen in ava Servle5P, ASP, PHP, Pel, Python, CSL and others,
wart. ecu 9 homelehchualprogranringibowd/Toreat HowToind wsns. How to Install Tomeat 7 (on Windows, Mac and Ubunty) and Got Started with Java Seret Programming
HTTP Client HTTP HTTP Server
(Browser) {over TCP/IP) (hostname :port)
aa Request Message
Programs
HTML pages, |= —
Forms, Applets
Gay <_Besponee Menge aa
TCP/IP Network
‘Server-side
Programs
‘Application “Te
Presentation ssl
Session
Transport TCP | Multiplexing (Port), Re-transmission
Network IP | Addressing (IP Adcress), Routing
Data Link | | TEEE802.4«
Physical
The typical usecase is
‘Aus v a web browser (HTTP con ssues a URL request to an HTTP server ta start a webapo.
‘A cbant-side program (ch a¢ an HTML fori dd int chins rows
‘The user fil up the quay ctr inthe frm.
The cess program sends the qury parameters to a sererside program,
‘The server-side program reeves the query parameters, queras the database and returs the query result tothe cent.
“The cnt-side program ispys the query resukon the browser.
The proces epee
1.2_ Hypertext Transfer Protocol (HTTP)
‘HTTP san oppication layer protocol runs over TCP/IP. The IP provides support for routing and adcresing (vi an unique IP adress for machines on the
Internet hie TCP supports multiplexing vi G4K ports rm port number 0 to 65535, The default prt number ssgned to HTTP ie TC por 80,
= HTP san esynchonous request response application layer protocol. clon sends 3 request message tothe server. The server then retuns a response
message tothe cent,
+ HIT sa pull protocol,» dent pul a page rom the sewer (stead of server pushes pages to the clans
= The syntax of the messages defined inthe HTP soxfation,
wart. ecu 9 homelehchualprogranringibowd/Toreat HowToind
218ns. How to Install Tomeat 7 (on Windows, Mac and Ubunty) and Got Started with Java Seret Programming
Request Message
GET /hone.heml HTTP /2.1
Host: xyz.com
HTTP Client(s) Connection: Keep-Alive
http://xyz.com/homehtml User-Agent: Mozilla/4.0
Accept: image/gif, image/jpeg | :
= "=== blank line 2 f
Gemcty touyy HTTP Server
al R M 1 server-side
cliente | jesponse Message ! sisal]
bene HrTP/1.1 208 OK a
Date:
=) (|_| server: apache/2.0.45
Last-Hodified:
Content-Length: 105
— ContentType: text/htal
= blank Line -
";
>
ut.printin(“epoeeee * s count + * records found
Drintin(-")s
sah (SQuEaception ex) {
er-pranestackirace();
éinalty ¢
cout.close():// Close the output weiter
11 Step 5: Close the resources
44 (seme I= null) stme-elose()s
1 (Eonn I= mall) cometose();
) teh (seLEception x) {
cx-pranestackirace()
Compile the source "QueryServiet. java" hto "QueryServiet class
Step 7(e) Configure the Request URL for the Servlet
open
the confguraton fle "web.xml" of your application "hello" that you have crested earler for the
wart. ecu 9 homelehchualprogranringibowd/Toreat HowToind
Helloserviet,
sains. How to Install Tomeat 7 (on Windows, Mac and Ubunty) and Got Started with Java Seret Programming
‘ webapps \helLO\HEB-INF eh. x8)" Add the ne that ae shown in rad at the LOCATIONS INDICATED,
1 cen version".2° encading="I50-8859-1°79
2 cab-app vorsion3.0"
3 omns"Ret: (aver sun.con/aml/ns/3ava0e”
4 andneixet-tnetpi/ wn. org/2001/20Schana-Lnstance
5 tchenatocation="hetp://Jova.sun-con/enl/ts/Javace Metp/Jav.sun.con/sm/ns/ eves ab-ape 9 8.984°>
we ‘eervlet-naveet Lorde
a “corvlet-rlnerstelioservlote/senvletelass>
2 Yseriet
% “serulet-navesUrerguerye/srvlet-nane>
6 ‘Serviet-class>Queryservletc/serviet-lass>
DP dsevie
B “rervletenaresseLoord/servlet-nane>
u ‘ark-pattert/saynelloc/uri-aattern>
25 esenviet-mplg>
By ‘Serviet-naweuserqurys/serviet-nane>
Fy fart-patters/querycfuni-pattern>
3a cjservlet-nspng®
Beye
‘The above lines configure the following URL to invoke QueryServiet:
eto: //localhest:9900/neLLo/query
Step 7(f) Invoke the Servlet
Jssue the follwing URL to browse the HMTL form “querybook. html” that you have crested eal:
om the Client-Side Form
to: //Localhest9808/nel10/querybook. tnd
‘Select an author fe, "Ton Ah Teck’ and dick the submit button, which states the felling URL coded in the