UpdateWeatherForecastServlet.java
上传用户:shen332233
上传日期:2021-09-03
资源大小:7478k
文件大小:1k
源码类别:

Ajax

开发平台:

Java

  1. package ajaxdashboard.servlet;
  2. import ajaxdashboard.service.WeatherForecastService;
  3. import java.io.*;
  4. import java.util.Date;
  5. import javax.servlet.*;
  6. import javax.servlet.http.*;
  7. public class UpdateWeatherForecastServlet extends HttpServlet {
  8.     protected void processRequest(HttpServletRequest request
  9.                                             , HttpServletResponse response)
  10.                                             throws ServletException, IOException {
  11.         
  12.         String zipCode = request.getParameter("forecastZipCode");
  13.         WeatherForecastService forecastService = new WeatherForecastService();
  14.         request.setAttribute("forecastData"
  15.                                     , forecastService.getForecastFor(zipCode));
  16.         
  17.         System.out.println("Weather updated at: " + new Date().toString());
  18.         
  19.         request.getRequestDispatcher("/jsp/weather/weatherForecastAjax.jsp")
  20.                                                     .forward(request, response);
  21.     }
  22.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  23.     throws ServletException, IOException {
  24.         processRequest(request, response);
  25.     }
  26.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  27.     throws ServletException, IOException {
  28.         processRequest(request, response);
  29.     }
  30. }