javaEE衡量生活质量课程设计报告_第1页
javaEE衡量生活质量课程设计报告_第2页
javaEE衡量生活质量课程设计报告_第3页
javaEE衡量生活质量课程设计报告_第4页
javaEE衡量生活质量课程设计报告_第5页
已阅读5页,还剩11页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、.PAGE :.; 设计时间年月日月日 设计目的JavaEE课程设计是对所学JavaEE与中间件课程的小结,是提高学生对所学知识综合运用才干的一种方式,是集中实际性环节之一。要求同窗们对课程中所学习到的知识综合运用,开发有一定规模的Java Web程序。设计义务设计生活质量衡量系统衡量规范阐明:消费有两种支出:吃饭支出和 其它支出,假设在一段时间内,吃饭支出占总支出的比例超越%,生活质量为贫困;假设在-%之间,为温饱;假设低于%,生活质量为小康。功能描画:用户以合法身份登录系统后,才干进展一切操作;用户可以添加、查看和删除支出情况支出类型有两种:吃饭支出和其它支出、额度人民币、日期。添加支出情

2、况查看支出情况删除支出情况统计在某个时间段内,生活质量属于哪个层次 设计内容 . 设计标题生活质量衡量系统。 .系统功能要求用只需拥有合法身份才干登录系统,用以合法身份登录后才干进展添加、查看和删除支出情况支出类型有两种:吃饭支出和其它支出、额度人民币、日期。. 数据库存储要求 数据的存储要求:吃饭支出其他支出,日期。.数据库的设计图 数据库存储表图数据库存储数据.系统构造关系 登陆窗口密码noyes操作界面计算删除插入查询 图jsp页面构造Jsp页面传送参数调用servlet类参数计算方法servlet删除方法servlet查询方法servlet插入方法servlet删除方法dao类查询方法

3、dao类插入方法dao类计算方法dao类图Java类功能调用. Jsp 页面设计.登录界面图登录界面代码如下: 欢迎登陆生活质量衡量系统! 用户称号: 用户密码: .登录胜利界面 图登录胜利查询界面 登陆胜利!点击获得详细的信息 .查询结果界面图查询结果界面.Java方法设计.Servlet类密码验证的Servlet类的代码如下:public class LoginServlet extends HttpServlet public void doGet(HttpServletRequest request, HttpServletResponse response)throws Servle

4、tException, IOException doPost(request,response);public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException String username = (String)request.getParameter(username);String userpsw = (String)request.getParameter(userpsw);System.out.println(usernam

5、e);String forward = ;if(username.equals() & userpsw.equals()forward = /success.jsp;elseforward = /error.jsp; 显示一切信息的servlet类代码设计如下:public class ListAllThingServlet extends HttpServlet public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException doPo

6、st(request,response);public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException ThingDAO thingDAO=new ThingDAO();List list=thingDAO.getAllThing();request.setAttribute(allthing, list);request.getRequestDispatcher(/showAllThing.jsp).forward(request

7、, response);控制增删改操作的servlet类代码设计如下:插入支出情况代码:public class SaveOutServlet extends HttpServlet public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException doPost(request,response);public void doPost(HttpServletRequest request, HttpServletResponse resp

8、onse)throws ServletException, IOException double x=.; double y=.; x=Double.parseDouble(request.getParameter(eating); y=Double.parseDouble(request.getParameter(others); String times=(String)request.getParameter(times); ThingDAO thingDAO=new ThingDAO(); try thingDAO.saveUser(x,y,times); catch(Exceptio

9、n e) e.printStackTrace(); List list=thingDAO.getAllThing();request.setAttribute(allthing, list);request.getRequestDispatcher(/showAllThing.jsp).forward(request, response);删除支出情况代码:public class DeleteOutServlet extends HttpServlet public void doGet(HttpServletRequest request, HttpServletResponse resp

10、onse)throws ServletException, IOException doPost(request,response);public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException double x=.; x=Double.parseDouble(request.getParameter(eating);ThingDAO thingDAO=new ThingDAO();try thingDAO.deleteUser(x

11、);catch(Exception e)e.printStackTrace();List list=thingDAO.getAllThing();request.setAttribute(allthing, list);request.getRequestDispatcher(/showAllThing.jsp).forward(request, response);衡量生活质量代码:public class Caculate extends HttpServlet public void doGet(HttpServletRequest request, HttpServletRespons

12、e response)throws ServletException, IOException doPost(request,response);public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException String time=request.getParameter(time); String time=request.getParameter(time); ThingDAO thingDAO=new ThingDAO();

13、try String resulte=thingDAO.caculate(time, time); request.setAttribute(resulte, resulte);request.getRequestDispatcher(/caculateresulte.jsp).forward(request,response); catch(Exception e) e.printStackTrace(); .Dao类显示一切支出情况的Dao类代码设计如下:public class ThingDAO public List getAllThing()Connection con=DBConn

14、ection.getConnection();List list=new ArrayList();tryStatement ps=con.createStatement();/Statement(select * from moneying);ResultSet rs=ps.executeQuery(select * from moneying);while(rs.next()Thing thing=new Thing();thing.setEating(rs.getDouble();thing.setOthers(rs.getDouble();thing.setTimes(rs.getStr

15、ing();list.add(thing);return list;catch(SQLException e)e.printStackTrace();finallyif(con!=null)trycon.close();catch(SQLException e)e.printStackTrace();return list;添加,删除和统计生活质量的Dao类代码设计如下:public boolean saveUser(double m, double n,String q) throws ExceptionConnection con = DBConnection.getConnection(

16、);String listSQL=insert into moneying values (?,?,?);PreparedStatement pstmt=con.prepareStatement(listSQL);trypstmt.setDouble(, m);pstmt.setDouble(, n);pstmt.setString(, q);pstmt.executeUpdate();conmit();return true;catch (SQLException e)con.rollback();e.printStackTrace();finallycon.close();return f

17、alse;public boolean deleteUser(double x)throws ExceptionConnection con=DBConnection.getConnection(); PreparedStatement pstmt=con.prepareStatement(delete from moneying where eating=?); try pstmt.setDouble(, x); pstmt.executeUpdate(); conmit(); return true; catch(SQLException e) con.rollback(); e.prin

18、tStackTrace(); finally con.close(); return false; public String caculate(String x,String x)/计算式温饱还是小康生活程度Connection con=DBConnection.getConnection();int i=;int j=;String SQL=select id from moneying where times=x;String SQL=select id from moneying where times=x;tryPreparedStatement psmt=con.prepareSt

19、atement(SQL);PreparedStatement psmt=con.prepareStatement(SQL);ResultSet rs=psmt.executeQuery();ResultSet rs=psmt.executeQuery();if(rs.next()i=rs.getInt();if(rs.next()j=rs.getInt();catch(SQLException e)e.printStackTrace();double eatingtotal=.;double total=.;int k=;for(k=i;k=j;k+)String SQL=seclect ea

20、ting,others from moneying where id=k;tryPreparedStatement psmt=con.prepareStatement(SQL);ResultSet rs=psmt.executeQuery();eatingtotal=eatingtotal+rs.getDouble();total=total+rs.getDouble()+rs.getDouble();catch(SQLException e)e.printStackTrace();if(eatingtotal/total.)return pinkun;elsereturnwenbao;.数据

21、库衔接类数据库衔接代码如下:public class DBConnection public static Connection getConnection()final String driverName=com.microsoft.jdbc.sqlserver.SQLServerDriver;final String url=jdbc:microsoft:sqlserverlocalhost:;databasename=mydb;tryClass.forName(driverName);catch(ClassNotFoundException e)e.printStackTrace();tryConnection con=Driver

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论