Demo: 1. Create Java Web Application

July 2025

Create a Java web application using JSP and Servlet, deploy it on Apache Tomcat, and display dynamic links generated by backend logic.

1. πŸ“ Project Structure Setup

Create a basic Maven or dynamic web project with the following structure:

MyWebApp/
β”œβ”€β”€ src/
β”‚   └── main/
β”‚       └── java/
β”‚           └── com/
β”‚               └── example/
β”‚                   β”œβ”€β”€ DemoServlet.java
β”‚                   β”œβ”€β”€ DemoApp.java
β”‚                   └── Demo2App.java
β”œβ”€β”€ web/
β”‚   └── index.jsp
β”œβ”€β”€ WEB-INF/
β”‚   β”œβ”€β”€ web.xml
β”œβ”€β”€ pom.xml

2. 🧠 Backend Logic

Ensure you have the following classes:

  • DemoServlet.java

  • DemoApp.java and Demo2App.java with static getMessage() methods:


3. πŸ“ JSP Page (index.jsp)

Create a JSP file that links to the servlet with different parameters:


4. 🧾 web.xml Configuration

Define the servlet and mapping in WEB-INF/web.xml:


5. πŸ§ͺ Using Maven Build and Package

3KB
Open
Sample pom xml file for reference

This will generate a WAR file in the target/ directory.


6. πŸš€ Deploy to Apache Tomcat

  • Copy the generated .war file to the webapps/ directory of your Tomcat installation.

  • Access the app at: http://localhost:8080/MyWebApp/


  1. βœ… Test the Application

  • Visit the root URL to see the JSP with two links.

  • Click each link to see the message from either DemoApp or Demo2App.

The first link without problem, it can display the website title
It cannot display the website title, because the URL is incorrect

Last updated

Was this helpful?