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

Ajax

开发平台:

Java

  1.  package ajaxdashboard.servlet;
  2. import ajaxdashboard.service.StockQuoteService;
  3. import ajaxdashboard.ws.stockquote.GetQuotesResponse;
  4. import ajaxdashboard.ws.stockquote.Quote;
  5. import java.io.*;
  6. import java.util.Date;
  7. import javax.servlet.*;
  8. import javax.servlet.http.*;
  9. public class UpdateStockQuoteServlet extends HttpServlet {
  10.     
  11.     protected void processRequest(HttpServletRequest request
  12.                                             , HttpServletResponse response)
  13.                                             throws ServletException, IOException {
  14.         
  15.         String stockTickers = request.getParameter("stockTickers").toUpperCase();
  16.         
  17.         GetQuotesResponse quotesResponse = 
  18.                        new StockQuoteService().getStockQuotesFor(stockTickers);
  19.         
  20.         Quote[] quotesArray = quotesResponse.getGetQuotesResult().getQuote();
  21.         
  22.         request.setAttribute("quotesArray", quotesArray);
  23.         
  24.         System.out.println("nn****nStock quotes updated at: " 
  25.                                                         + new Date().toString());
  26.         
  27.         request.getRequestDispatcher("/jsp/stockQuote/stockQuoteAjax.jsp")
  28.                                                 .forward(request, response);
  29.     }
  30.     
  31.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  32.     /** Handles the HTTP <code>GET</code> method.
  33.      * @param request servlet request
  34.      * @param response servlet response
  35.      */
  36.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  37.     throws ServletException, IOException {
  38.         processRequest(request, response);
  39.     }
  40.     
  41.     /** Handles the HTTP <code>POST</code> method.
  42.      * @param request servlet request
  43.      * @param response servlet response
  44.      */
  45.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  46.     throws ServletException, IOException {
  47.         processRequest(request, response);
  48.     }
  49.     
  50.     /** Returns a short description of the servlet.
  51.      */
  52.     public String getServletInfo() {
  53.         return "Short description";
  54.     }
  55.     // </editor-fold>
  56. }