balanceservlet.java

来自「Java完全自学手册 全部随书代码 作者:马军 王灏」· Java 代码 · 共 55 行

JAVA
55
字号
package family.yin.senqi;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Date;
import java.util.Calendar;
import family.yin.senqi.dao.MyDAO;
import family.yin.senqi.model.ModelFour;
import java.sql.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class BalanceServlet extends HttpServlet {
  public void doPost(HttpServletRequest req, HttpServletResponse resp)
  throws ServletException, IOException
  {
    HttpSession session = req.getSession();
    Calendar c = Calendar.getInstance();
    int nYear = c.get(1);
    int nMonth = c.MONTH+1;
    String nYear_str = req.getParameter("nYear");
    String nMonth_str = req.getParameter("nMonth");
    if(nMonth_str!=null && nYear_str!=null){
      nMonth = new Integer(nMonth_str).intValue();
    }
    MyDAO dao = new MyDAO();
    try {
      ModelFour[] mf = dao.getBalance(nYear, nMonth);
      session.setAttribute("mf",mf);
      float mTotal = dao.getMonthTotalMoney(nMonth);
      session.setAttribute("mTotal",new Float(mTotal));
    }
    catch (SQLException ex) {
      ex.printStackTrace();
    }
    resp.sendRedirect("balance.jsp?nYear="+nYear+"&nMonth="+nMonth);
  }

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
  throws ServletException, IOException
  {
    this.doPost(req,resp);
  }


}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?