Giter Site home page Giter Site logo

darshanbajgain / weather-app-javaservletjsp Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 519 KB

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.

Java 56.12% HTML 8.92% CSS 30.48% JavaScript 4.48%
java java-web-app jsp openweather servlet servlet-jsp weather

weather-app-javaservletjsp's Introduction

WeatherApp USING JAVA SERVLET JSP

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 <repository_url>.
  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

WeatherApp Screenshot

WeatherApp Screenshot

WeatherApp Screenshot

Created by:

weather-app-javaservletjsp's People

Contributors

darshanbajgain avatar

Stargazers

 avatar

Watchers

 avatar

weather-app-javaservletjsp's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.