全文预览

Servlet的MVC模式(计算等差、等比数列的和)

上传者:随心@流浪 |  格式:doc  |  页数:7 |  大小:22KB

文档介绍
etRequestDispatcher("showResult.jsp");34dispatcher.forward(request,response);//请求showResult.jsp显示shulie中的数据35}3637publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{38Seriesshulie=newSeries();39request.setAttribute("lie",shulie);40doublea=Double.parseDouble(request.getParameter("firstItem"));41doubled=Double.parseDouble(request.getParameter("var"));42intn=Integer.parseInt(request.getParameter("number"));43shulie.setFirstItem(a);44shulie.setVar(d);45shulie.setNumber(n);46//计算和:47doublesum=0,item=a;48inti=1;49shulie.setName("等比数列的公比");50while(i<=n)//计算等比数列的和51{52sum=sum+item;53i++;54item=item*d;55}56shulie.setSum(sum);57RequestDispatcherdispatcher=request.getRequestDispatcher("showResult.jsp");58dispatcher.forward(request,response);59}60}

收藏

分享

举报
下载此文档