0% found this document useful (0 votes)
30 views

WEBD4201 Lab 3 Demo

The document provides instructions for students to set up their laptops with the necessary software and configurations to run a demo web application for a lab. This includes downloading Java, Tomcat, PostgreSQL, and other libraries. Students are instructed to configure environment variables, set up the database, deploy the demo web application to Tomcat, and import code files into an Eclipse project to test the application.

Uploaded by

asheshd11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

WEBD4201 Lab 3 Demo

The document provides instructions for students to set up their laptops with the necessary software and configurations to run a demo web application for a lab. This includes downloading Java, Tomcat, PostgreSQL, and other libraries. Students are instructed to configure environment variables, set up the database, deploy the demo web application to Tomcat, and import code files into an Eclipse project to test the application.

Uploaded by

asheshd11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

WEBD4201 Lab 3 Demo

Students are encourage to configure their laptops so that the example provided works. This will can become a start
point for Deliverable 3.

Software Setup:
In DC Connect in the “Software” section of the course, download the following:

 apache-tomcat-8.0.18-windows-x64.zip
 postgresql-9.4-1200.jdbc41.jar
 servlet-api.jar
 jsp-api.jar

TomCat Web Server


Unzip the Apache Tomcat folder and place the “Tomcat8.0” folder wherever you want it on your laptop.

Navigate into the Tomcat8.0/bin folder, right-mouse click on startup.bat and shutdown.bat and “Send
to” -> “Desktop (create shortcut)”

Cut and paste the postgresql-9.4-1200.jdbc41.jar, servlet-api.jar and jsp-api.jar files into the
Tomcat8.0/lib folder.

For Tomcat to run, there needs to be three (3) System environment variable define. Go to Start -> Control
Panel -> System -> Advanced System Settings.

Select the “Advanced” tab, click on “Environment Variables” and under “System variables” create a JAVA_HOME, a
JRE_HOME and CATALINA_HOME variables. Use the browse button to navigate to your JDK and JRE folders in
your C:\Program Files\Java\ directory.
NOTE: the _1.8.0_25 below may differ from the version numbers for your JDK and JRE.

 JAVA_HOME C:\Program Files\Java\jdk_1.8.0_25


 JRE_HOME=C:\Program Files\Java\jre_1.8.0_25
 CATALINA_HOME=C:\WHERE_EVER_YOIU_UNZIPPED_TOMCAT\Tomcat8.0
Open up cmd.exe (a DOS window) as an administrator, navigate to the C:\...\Tomcat8.0\bin folder and at
the prompt enter: startup.bat

NOTE: if Tomcat does not start up successfully for you, try re-starting your laptop and repeating the last step as the
environmental variables may not have become active yet.

Open a browser and go to localhost:8080, you should be welcomed to the Tomcat welcome page. Click on
“Manager App” in the top right corner, and enter “admin” for user id and nothing for the password (NOTE: the
users are managed WEBD4201 Deliverable 3 Demo

in the Tomcat8.0/conf/tomcat-users.xml file, if you open this file you will see the “admin” role setup).

You should see a few existing applications that Tomcat is already running. One of which is “Manager”, which the is
the manager tool that you have logged in with.

Database Requirements:
In pgAdmin on your laptop, create a new user named db_user if you do not already have one, with a password of
db_password and then assign ownership of a new database named demo_db to that user.
Select the new demo_db and run the SQL script deliverable3_demo/sql/deliverable3_db.sql found in
zip file provided

Tomcat Web Application Setup:


Copy the demo folder from the deliverable3_demo.zip file and paste it, in its entirety, into the
Tomcat8.0/webapps folder (if you have not already done so).

If you refresh the Manager app at http://localhost:8080/manager/html you should see a new demo
Application. Right-mouse click on the /demo link in the Application paths and click “Open link in new tab”

Java Requirements:
Create a new project in Exclipse named Lab3Example. Import into the src directory *.java files found in the
provided zip file.

You will have to add postgresql-9.4-1200.jdbc41.jar, servlet-api.jar, and jsp-api.jar archives


into the library of your new project to get servlets to compile.

In Eclipse: Right mouse-click on your project. Click “Properties -> Java Build Path”. Select “Libraries” tab, and click
“Add External JARs”. Browse to where you have built your Tomcat, go into Tomcat 8.0/lib folder select serlvet-
api.jar and jsp-api.jar and click Open, click Ok

You should be able to build the project into its demo/*.class files. In order for your demo application to use the
files you should place the complete demo folder with its class files contained in the
Tomcat8.0/webapps/demo/WEB-INF/classes folder. Go back to the Tomcat manager and click on the
“Reload” button for the demo application (YOU HAVE TO CLICK “Reload” ANYTIME YOU MAKE A CHANGE TO ANY
CLASS FILE IN THE WEB-INF/classes FOLDER).

NOTE: you should be able to run the provided Lab3DemoTester.java file at this point and get a record back onto
the console.

If you go back to the http://localhost:8080/demo/ page, click on “Login”, and then enter a phone number from the
database (e.g. “123-4567”), it should retrieve the user’s information from the database and display it on the
“customerUpdate.jsp” page.

NOTE: for debug purposes, any System.out.println() method calls in your programs will be displayed in the Tomcat
window.

Web XML Explained


For any servlet to be used with an HTML form, it has to have two (2) XML elements to tell Tomcat where to find a
Servlet, and how the web request will refer to it:

<servlet>
<servlet-name>UpdateCustomerServlet</servlet-name>
<servlet-class>demo.UpdateCustomerServlet</servlet-class>
</servlet>
The <servlet> element gives a name to a servlet and informs Tomcat where it will be found in the
WEB-INF/classes folder (in this case, there will be a demo package/folder and a LoginServlet.class file there)

<servlet-mapping>
<servlet-name>UpdateCustomerServlet</servlet-name>
<url-pattern>/AnyPattern</url-pattern>
</servlet-mapping>
The <servlet-mapping> element gives the name of a servlet and defines what URL pattern the server will
receive from an HTML form to access the servlet. E.g.

<form method="post" action="./AnyPattern">

You might also like