当前位置:跳过导航链接计算机毕业设计首页 : JAVA计算机毕业设计 : 详细内容

JSP家庭理财管理系统(18)

来源:xiaoniu168.com 作者:JSP 添加时间:2011-09-18 点击数:45277

计算机毕业设计主要代码3:

下面简单说一下BanlanceServlet.java这个处理所有关于“*.look”页面的Servlet.主要代码如下:
public class BalanceServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;

public void doPost(HttpServletRequest req, HttpServletResponse resp)
  throws ServletException, IOException
  {
    HttpSession session = req.getSession();//得到连接的session
    Calendar c = Calendar.getInstance();
    int nYear = c.get(1);
    int nMonth = Calendar.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 (Exception 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);
  } }
其中的getBalance(nYear, nMonth)方法的作用是把和数据库连接同时处理封装好的数据,并把处理好的数据返回给页面展示。

<责任编辑:计算机毕业设计网(http://www.xiaoniu168.com)>

【联系方式】

【本站信誉】

用心做计算机毕业设计论文网