图4.2.3.1 计划添加界面
输入必要信息后,点击确认添加的“添加”按钮,即可实现此次计划的添加。 “添加”实际就是对数据库信息的添加。对数据库信息的添加是当用户需要制定新的计划时所需要的功能,在计划管理中,需要实现的功能是新计划的制定,添加的内容是计划序号,计划名称,计划描述,发布人,发布时间。 完成此功能的步骤是: 首先新建一个客户端JSP页面beforeJHBADD.jsp,在其中设置五个文本框用来填计划序号,计划名称,发布时间,发布人,计划描述。通过点击添加确认的“添加”按钮,执行JHBADD.jsp页面中的算法,此过程需要的代码为: <body> <form action="JHBADD.jsp" name="myform" method="post"> 计划序号: <input type="text" JHMC="JHXH"><br> 计划名称: <input type="text" JHMC="JHMC"><br> 计划描述: <input type="text" JHMC="JHMS"><br> 发布人 : <input type="text" JHMC="FBR"><br> 发放时间 :<input type="text" JHMC=" FBSJ"><br> <input type="submit" value="添加"> </form> </body>
然后再新建一个服务器端JSP页面(JHBADD.jsp),在此页中书写完成对新计划的添加功能的代码,其代码为: <body> <% String JHXH = request.getParameter("JHXH"); String JHMC = request.getParameter("JHMC"); String JHMS = request.getParameter("JHMS"); String FBR = request.getParameter("FBR"); String FBSJ = request.getParameter("FBSJ"); //从文本框中读入要添加进数据库的信息 Connection con =null; PreparedStatement psm = null; ResultSet rs = null; try{ Class.forname("com.mysql.jdbc.Driver").newInstance(); String url = "jdbc:mysql://localhost/test"; con = DriverManager.getConnection(url,"root","****"); //连接数据库,数据库用户名为“root”“****”表示数据库的密码 psm = con.prepareStatement("insert into OA_JHB values(?,?,?,?,?)"); psm.setString(1,JHXH); psm.setString(2,JHMC); psm.setString(3,JHMS); psm.setString(4,FBR); psm.setString(5,FBSJ); psm.executeUpdate( ); //将读入的值存进数据库的四个列中 response.sendRedirect("OA_JHB.jsp"); //如果存放成功,则转到OA_JHB.jsp页面,即计划管理界面 } catch(Exception e){ response.sendRedirect("beforeJHBADD.jsp"); //如果不成功,则返回添加界面 } finally { if(rs!=null){ try{ rs.close();}catch(Exception e){e.printStackTrace();} } if(psm!=null){ try{ psm.close();}catch(Exception e){e.printStackTrace();} }
首页 上一页 7 8 9 10 11 12 13 下一页 尾页 10/14/14