StockQuoteServlet.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 java.io.*;
  5. import java.net.*;
  6. import javax.servlet.*;
  7. import javax.servlet.http.*;
  8. public class StockQuoteServlet extends HttpServlet {
  9.     
  10.     /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  11.      * @param request servlet request
  12.      * @param response servlet response
  13.      */
  14.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  15.     throws ServletException, IOException {
  16.         response.setContentType("text/html;charset=UTF-8");
  17.         PrintWriter out = response.getWriter();
  18.         /* TODO output your page here
  19.         out.println("<html>");
  20.         out.println("<head>");
  21.         out.println("<title>Servlet StockQuoteServlet</title>");
  22.         out.println("</head>");
  23.         out.println("<body>");
  24.         out.println("<h1>Servlet StockQuoteServlet at " + request.getContextPath () + "</h1>");
  25.         out.println("</body>");
  26.         out.println("</html>");
  27.          */
  28.         
  29.         GetQuotesResponse quotesResponse = new StockQuoteService().getStockQuotesFor("DCX");
  30.         request.setAttribute("quotesResponse", quotesResponse);
  31.         request.getRequestDispatcher("/stockQuote.jsp").forward(request, response);
  32. //        out.close();
  33.     }
  34.     
  35.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  36.     /** Handles the HTTP <code>GET</code> method.
  37.      * @param request servlet request
  38.      * @param response servlet response
  39.      */
  40.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  41.     throws ServletException, IOException {
  42.         processRequest(request, response);
  43.     }
  44.     
  45.     /** Handles the HTTP <code>POST</code> method.
  46.      * @param request servlet request
  47.      * @param response servlet response
  48.      */
  49.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  50.     throws ServletException, IOException {
  51.         processRequest(request, response);
  52.     }
  53.     
  54.     /** Returns a short description of the servlet.
  55.      */
  56.     public String getServletInfo() {
  57.         return "Short description";
  58.     }
  59.     // </editor-fold>
  60. }