An open API service indexing awesome lists of open source software.

https://github.com/pratikkhot100/weather-web-application

Weather Application is a Java web application developed using Servlets, JSP, HTML, CSS, and JavaScript. It integrates with the OpenWeatherMap API to fetch weather data for a given city and display it to the user.
https://github.com/pratikkhot100/weather-web-application

java java-web-application jsp openweathermap-api servlet weather

Last synced: about 1 month ago
JSON representation

Weather Application is a Java web application developed using Servlets, JSP, HTML, CSS, and JavaScript. It integrates with the OpenWeatherMap API to fetch weather data for a given city and display it to the user.

Awesome Lists containing this project

README

        

# Weather_web_application

## Description
WeatherApp is a simple Java web application developed using Servlets, JSP, HTML, CSS, and JavaScript. It integrates with the OpenWeatherMap API to fetch weather data for a given city and display it to the user.

## Features
Fetch weather data based on the user's input city name.
Display current weather conditions including temperature, humidity, wind speed, visibility, and cloud cover, etc.

## Technologies Used
- Java Servlets
- JavaServer Pages (JSP)
- HTML
- CSS
- JavaScript
- Gson library for JSON parsing
- OpenWeatherMap API

## Setup Instructions
1. Download and install Eclipse IDE (or IntelliJ IDEA).
2. Download and install Apache Tomcat 10.1.1.
3. Open Eclipse IDE and configure it with Apache Tomcat:
- Go to `Window` -> `Preferences`.
- Navigate to `Server` -> `Runtime Environments`.
- Click `Add` and select `Apache Tomcat v10.1.1`.
- Provide the Tomcat installation directory and finish the setup.
4. Clone the repository to your local machine using `git clone `.
5. Import the project into Eclipse IDE:
- Go to `File` -> `Import`.
- Select `Existing Projects into Workspace`.
- Choose the cloned project directory and import it into Eclipse.
6. Ensure that the Gson library is included in the `src/webapp/WEB-INF/lib` directory of your project. If not, add it manually to the build path.
7. Obtain an API key from OpenWeatherMap and replace the placeholder `myApiKey` in `MyServlet.java` with your actual API key.
8. Run the application on your local Apache Tomcat server:
- Right-click on the project in Eclipse.
- Go to `Run As` -> `Run on Server`.
- Select your configured Tomcat server and click `Finish`.
9. Access the WeatherApp through your web browser using the provided URL (usually `http://localhost:8080/WeatherApp`).

## API Integration in Servlet:
- Created a Java servlet (MyServlet.java) to handle HTTP requests.
- In the doPost method, fetched the city name from the form input.
- Constructed the API URL with the city name and your API key (apiUrl) to fetch weather data.

### HTTP Request to API:
- Used HttpURLConnection to establish a connection to the API endpoint.
- Set the request method to GET and retrieved the API response using input streams.

### Processing API Response:
- The API response was in JSON format.
- Used the Gson library to parse the JSON response into a JsonObject.
- Extracted relevant weather data like temperature, humidity, wind speed, visibility, weather condition, and cloud cover from the JSON response.

### Setting Request Attributes:

- Stored the extracted weather data, city name, date, time, and other relevant information as request attributes using HttpServletRequest.setAttribute().

### Forwarding Request to JSP:

- Forwarded the request to the JSP page (index.jsp) for rendering using RequestDispatcher.forward().

## Displaying Data in JSP:

- In our JSP page (index.jsp), we used HTML and embedded Java code (EL expressions) to display the weather data.
- Accessed the data from request attributes using ${attributeName} syntax.

## Screenshots

![Screenshot 2025-04-08 005632](https://github.com/user-attachments/assets/da5611ff-8a59-4855-b24f-d7ce34c3b146)

![Screenshot 2025-04-08 005650](https://github.com/user-attachments/assets/95a9d40b-5550-44ee-a9d0-2e857c3ccf6c)

![Screenshot 2025-04-08 005809](https://github.com/user-attachments/assets/4a924359-9aaa-4377-856d-b5222f3f1359)

![Screenshot 2025-04-08 005942](https://github.com/user-attachments/assets/7a4d38cb-6a21-41c9-a09f-f1afdf7c5c34)

## Created by:
- [Pratik Khot](https://github.com/pratikkhot100)