Tomcat Setup BCIS 3680 Enterprise Programming. Getting Web Apps to Work Verify that Tomcat works. ...

Preview:

Citation preview

Tomcat Setup

BCIS 3680 Enterprise Programming

2

Getting Web Apps to Work Verify that Tomcat works. Understand how context works. Create folders/files for easy deployment of

your web app. Configure server.xml. Configure web.xml. Test your web app.

3

Verification of Tomcat Start a command prompt and run command: catalina run Tomcat is up if you see “INFO: Server startup in #### ms”

4

Exiting Tomcat To exit Tomcat, get back to the command console. Press CTRL + C simultaneously. When asked whether to terminate batch job, type y and hit

ENTER. You often need to stop and restart Tomcat after making

changes to configurations or class files.

5

Alias for Web App A web application consists of a collection of files that

are required to support a particular feature or task you want to publish to the outside world. The set of files are stored in a folder, which is the “deployment folder” for the application. It can contain subfolders.

When provide visitors with the URL to your web app, you don’t want to show them the physical path to the deployment folder.

Instead, you create an “alias” (or “context” or “virtual directory”) for the folder. In the URL, it is appended to the server name. Append any file names and/or subfolder names to the alias

when accessing files directly under the deployment folder or under one of its subfolders.

6

Alias (Context)This is what you want

your visitors to type and see . The application appears to be the \

casej03 “subfolder” on the server (localhost in

this case)

7

Deployment FolderThis is what your visitors DON’T see. This is where your web application files

are actually located at. You don’t want visitors to

know it.

8

Folders for Deployment Inside the deployment folder, create a

subfolder called WEB-INF. For testing and assignments, download the web.xml file into this subfolder.

9

Making the Connection

You define what you want the user to see (alias) as the

“path” attribute of the <Context> tag. Note the /

in front of the alias.

Set the value of the “docBase” attribute of the <Context> tag to

your deployment folder location.

For each alias, you need to add a new <Context> tag under the <Host> tag.

XML is case-sensitive!

10

Setting Up a Context One way to define an alias (context) is do it in

the server.xml configuration file. server.xml is located in \<Tomcat Folder>\

conf\. In the course VM, it’s C:\Tomcat\conf.

You may use any editor that is capable of editing XML files to open it. In the course VM, use Notepad++. If you use Windows Notepad, you will need to open

it with administrator rights. Otherwise you won’t be able to save the changes you make.

11

Start NotePad with Admin Rights

Again, open Notepad with administrator rights if you use Windows Vista or higher

12

Start NotePad with Admin Rights

13

Context for Web Applications Unlike HTML, XML is case-sensitive!

Inside the “Host” element (tag), modify the “Context” element. For example:<Context path="/jsp" docBase="E:/BCIS 3680/jsp" />

Restart Tomcat.

14

Testing Web Site After you have complete all the previous

steps, you can verify whether your web site is up and running by:

First, start Tomcat server from command prompt.

Second, open the browser and enter the following URL:http://localhost:8080/<context>/default.htm Replace the <context> part with the alias you

defined in the server.xml file.

15

Testing localhost Site Under Win7/Vista

1

23

Recommended