/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.web;

import com.ejb.StatefulAccountLocal;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
@WebServlet(name = "TestStatefulAccount", urlPatterns = {"/TestStatefulAccount"})
public class TestStatefulAccount extends HttpServlet {
   @EJB         
    StatefulAccountLocal statefulAccountBean;

   // @EJB
   // private StatefulAccountRemote statefulAccountBean;
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String id=request.getParameter("ID");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestStatefulAccount</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("the account balance:"+statefulAccountBean.getBalance(id)+"<br>");
//		向基金账户增加5000.25
        try{
        statefulAccountBean.depoist(2389.25);
        out.println("method of depoist(2389.25) Result:"+statefulAccountBean.getBalance(id)+"<br>");
//		从基金账户调出1000.02
        statefulAccountBean.withdraw(1000.02);
        out.println("method of withdraw(1000.02) Result:"+statefulAccountBean.getBalance(id));
        out.println("<hr>");
        out.println("current account balance:"+statefulAccountBean.getBalance(id));
        statefulAccountBean.updateAccount(id);
         }catch(Exception e){
             System.out.println(e.toString());
         }
        out.println("</body>");
        out.println("</html>");
        out.close();
      }


    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

   
}
