A full-stack Java web application built with Servlets, JSP, and the OpenWeatherMap API to deliver real-time weather forecasts.
- Description
- Screenshots
- Features
- Architecture & Workflow
- Technologies Used
- Setup Instructions
- API Integration Details
- Author
WeatherApp is a robust, dynamic Java-based web application that fetches and displays real-time weather data. It is developed using Java Servlets, JavaServer Pages (JSP), HTML, CSS, and JavaScript. By integrating seamlessly with the OpenWeatherMap API, the application dynamically updates based on the user's city input, returning essential meteorological data like temperature, humidity, wind speed, and visibility.
| Home Page / Search | Weather Data Display | Detailed Metrics |
|---|---|---|
![]() |
![]() |
![]() |
- Real-Time Data Fetching: Instantly retrieves live weather data based on the provided city name.
- Comprehensive Metrics: Displays detailed current weather conditions including:
- 🌡️ Temperature
- 💧 Humidity
- 💨 Wind Speed
- 👁️ Visibility
- ☁️ Cloud Cover
- Dynamic UI: A clean, responsive front-end built with HTML, CSS, and JavaScript.
- MVC Pattern Structure: Separates business logic (Servlet) from the presentation layer (JSP).
- Client Request: The user submits a city name via the HTML form on
index.jsp. - Controller (Servlet):
MyServlet.javahandles the HTTP POST request. - API Integration: The Servlet constructs an API call to OpenWeatherMap using
HttpURLConnection. - Data Parsing: The JSON response is parsed into Java objects using the Gson library.
- Data Transfer: Weather attributes are mapped and set to
HttpServletRequestattributes. - View (JSP): The request is forwarded to
index.jsp, where Expression Language (EL) is used to render the data dynamically.
Backend:
- Java Servlets (Controller & Business Logic)
- Gson Library (JSON Parsing)
Frontend:
- JavaServer Pages (JSP) (Dynamic Views & EL)
- HTML5 & CSS3 (Structure & Styling)
- JavaScript (Client-side interactivity)
Server & Tools:
- Apache Tomcat 10.x (Web Server / Servlet Container)
- Eclipse IDE / IntelliJ IDEA
- OpenWeatherMap REST API
- Java Development Kit (JDK) 11 or higher
- Apache Tomcat 10.1.x
- Eclipse IDE for Enterprise Java (or IntelliJ IDEA Ultimate)
- OpenWeatherMap API Key
-
Clone the Repository
git clone https://github.com/naamsanamone/WeatherApp.git
-
Configure IDE & Server
- Open Eclipse IDE.
- Go to
Window->Preferences->Server->Runtime Environments. - Click
Add, selectApache Tomcat v10.1.x, and point to your Tomcat installation directory.
-
Import Project
- Go to
File->Import->Existing Projects into Workspace. - Select the cloned
WeatherAppdirectory.
- Go to
-
Add Gson Dependency
- Ensure
gson-x.x.x.jaris present insrc/main/webapp/WEB-INF/lib. - If missing, download it and manually add it to the project's Build Path.
- Ensure
-
Configure API Key
- Sign up at OpenWeatherMap to get an API key.
- Open
src/main/java/MyPackage/MyServlet.java. - Replace the placeholder
myApiKeywith your actual API key:String apiKey = "YOUR_ACTUAL_API_KEY_HERE";
-
Run the Application
- Right-click the project in Eclipse ->
Run As->Run on Server. - Select your configured Tomcat instance.
- Access the app at:
http://localhost:8080/WeatherApp
- Right-click the project in Eclipse ->
- Utilizes
java.net.HttpURLConnectionto establish aGETrequest to the OpenWeatherMap API endpoint. - Reads the response via
InputStreamReaderandScanner.
- The raw JSON string is parsed into a
JsonObjectusing Google's Gson library. - Extracts deeply nested fields (e.g.,
main.temp,wind.speed,weather[0].main).
- The parsed values are passed to the frontend using
request.setAttribute(). - Uses
RequestDispatcher.forward(request, response)to seamlessly renderindex.jspwithout a redirect.
Sai Venkat
- GitHub: @naamsanamone
Developed with Java, Servlets, and the OpenWeather API.


