Lab 4 Servlets
Lab 4 Servlets
Lab 4 Servlets
• Open the pom.xml file and add the following (immediately before the Build tag):
<dependencies>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>9.0.1</version>
</dependency>
</dependencies>
• Within the New Server window, select Apache>Tome v9.0 Server and then select “Next >”
Lab 4 – Servlets
Add a Server
• Within the New Server window, use Browse… to locate and set the Tomcat Installation directory 1
• Select “Finish” to create the Tomcat Server
Lab 4 – Servlets
Edit the index.html file and add a hyperlink to pass a first_name and a last_name as
parameters using a GET method (which is the default)
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="Home?first_name=tony&last_name=stark">Click Me</a>
</body>
</html>
Lab 4 – Servlets
Create a Servlet
• Within the Project Explorer right click on the Java Resources, select New>Servlet
• Within the Create Servlet window enter a Java package name of “com.example”, enter a Class name of
“Home”, and then select “Finish”
Lab 4 – Servlets
Edit the Servlet file and modify the doGet method to read the first_name and
last_name, and output their values