10月30号
今天进行了Java课程的期中考试,获得了18.5分(满分20),很满足了,这么长时间的努力感觉非常值得了。下面是其中几个页面的源代码
index1.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>生产计划管理系统</title> </head> <body> <div id="container"> <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10" style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500"> <tr> <th>请选择要进行的操作</th> </tr> <form action="add.jsp" method="post" target="_self"> <tr> <td>新增生产计划</td> <td> <input type="submit" value="跳转"> </td> </tr> </form> <form action="findup.jsp" method="post" target="_self"> <tr> <td>修改生产计划</td> <td> <input type="submit" value="跳转"> </td> </tr> </form> <form action="findde.jsp" method="post" target="_self"> <tr> <td>删除生产计划</td> <td> <input type="submit" value="跳转"> </td> </tr> </form> <form action="find.jsp" method="post" target="_self"> <tr> <td>查询生产计划</td> <td> <input type="submit" value="跳转"> </td> </tr> </form> <form action="look.jsp" method="post" target="_self"> <tr> <td>查看所有生产计划</td> <td> <input type="submit" value="跳转"> </td> </tr> </form> </table> </div> </body> </html>
add.jsp
<%@ page import="java.sql.Connection" %> <%@ page import="java.sql.DriverManager" %> <%@ page import="java.sql.Statement" %> <%@ page import="java.sql.ResultSet" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>添加信息</title> </head> <body> <form action="addfinish.jsp" method="post" target="_self"> <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="100" style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500"> <tr> <th colspan=2>添加生产计划</th> </tr> <tr> <td>计划编号</td> <td><input type="text" name="id" ></td> </tr> <tr> <td>计划名称</td> <td><input type="text" name="name" ></td> </tr> <tr> <td>计划概述</td> <td><input type="text" name="talk" ></td> </tr> <tr> <td>排产方式</td> <td> <input type="radio" name="way" value="串行排产">串行排产  <input type="radio" name="way" value="并行排产">并行排产  <input type="radio" name="way" value="串并行排产">串并行排产 </td> </tr> <tr> <td>开始时间</td> <td><input type="date" name="opentime" ></td> </tr> <tr> <td>结束时间</td> <td><input type="date" name="closetime" ></td> </tr> <tr> <td>包含工艺</td> <td> <input type="checkbox" name="tech" value="锯">锯  <input type="checkbox" name="tech" value="热">热  <input type="checkbox" name="tech" value="车">车  <input type="checkbox" name="tech" value="铣">铣  <input type="checkbox" name="tech" value="钳">钳  <input type="checkbox" name="tech" value="去">去  <input type="checkbox" name="tech" value="珩">珩  <input type="checkbox" name="tech" value="表镀铬">表镀铬  <input type="checkbox" name="tech" value="表喷砂">表喷砂  <input type="checkbox" name="tech" value="综检">综检  <input type="checkbox" name="tech" value="洗">洗  <input type="checkbox" name="tech" value="包">包  <input type="checkbox" name="tech" value="入">入  <input type="checkbox" name="tech" value="装">装 </td> </tr> <tr> <th colspan=2><input type="submit" value="提交"></th> </tr> </table> </form> </body> </html>
addfinish.jsp
<%@ page import="java.sql.*" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>添加成功</title> </head> <body> <% String id=request.getParameter("id"); String name=request.getParameter("name"); String talk=request.getParameter("talk"); String way=request.getParameter("way"); String otime=request.getParameter("opentime"); String ctime=request.getParameter("closetime"); String[] tech=request.getParameterValues("tech"); if(name.length()>50||talk.length()>500){ response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); String newLocn = "index2.jsp"; response.setHeader("Location",newLocn); } try{ Class.forName("com.mysql.cj.jdbc.Driver"); // 2.使用我自己的数据库 test 获取链接 String url = "jdbc:mysql://localhost:3306/test"; String username = "root"; String password = "123456"; Connection connection = DriverManager.getConnection(url, username, password); //获取执行sql的对象statement Statement statement = connection.createStatement(); String t=""; for(int i=0;i<tech.length;i++){ t+=tech[i]+","; } String sql2="select * from plan"; ResultSet res=statement.executeQuery(sql2); while(res.next()) { if(id.equals(res.getString("计划编号"))){ response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); String newLocn = "index2.jsp"; response.setHeader("Location",newLocn); break; } } String sql="insert into plan(计划编号,计划名称,计划概述,排产方式,开始时间,结束时间,包含工艺) value(?,?,?,?,?,?,?)"; PreparedStatement ps1=connection.prepareStatement(sql); ps1.setString(1,id); ps1.setString(2,name); ps1.setString(3,talk); ps1.setString(4,way); ps1.setString(5,otime); ps1.setString(6,ctime); ps1.setString(7,t); ps1.executeUpdate(); ps1.close(); connection.close(); }catch(Exception e){ System.out.println(e); } %> <form action="index1.jsp" method="post" target="_self"> <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="100" style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500"> <tr> <th colspan=7>生产计划浏览</th> </tr> <td>计划编号</td> <td>计划名称</td> <td>计划概述</td> <td>排产方式</td> <td>开始时间</td> <td>结束时间</td> <td>包含工艺</td> <% pageContext.setAttribute("s1",id); pageContext.setAttribute("s2",name); pageContext.setAttribute("s3",talk); pageContext.setAttribute("s4",way); pageContext.setAttribute("s5",otime); pageContext.setAttribute("s6",ctime); pageContext.setAttribute("s7",tech); %> <tr> <td>${s1}</td> <td>${s2}</td> <td>${s3}</td> <td>${s4}</td> <td>${s5}</td> <td>${s6}</td> <td>${s7}</td> </tr> <% try{ Class.forName("com.mysql.cj.jdbc.Driver"); // 2.使用我自己的数据库 test 获取链接 String url = "jdbc:mysql://localhost:3306/test"; String username = "root"; String password = "123456"; Connection connection = DriverManager.getConnection(url, username, password); //获取执行sql的对象statement Statement statement = connection.createStatement(); String sql2="select * from plan"; ResultSet res=statement.executeQuery(sql2); while(res.next()){ String s1=res.getString("计划编号"); if(s1.equals(id)) break; String s2=res.getString("计划名称"); String s3=res.getString("计划概述"); String s4=res.getString("排产方式"); String s5=res.getString("开始时间"); String s6=res.getString("结束时间"); String s7=res.getString("包含工艺"); pageContext.setAttribute("p1",s1); pageContext.setAttribute("p2",s2); pageContext.setAttribute("p3",s3); pageContext.setAttribute("p4",s4); pageContext.setAttribute("p5",s5); pageContext.setAttribute("p6",s6); pageContext.setAttribute("p7",s7); %> <tr> <td>${p1}</td> <td>${p2}</td> <td>${p3}</td> <td>${p4}</td> <td>${p5}</td> <td>${p6}</td> <td>${p7}</td> </tr> <% } }catch (Exception e){ System.out.println(e); } %> <tr> <th colspan=7><input type="submit" value="返回首页"></th> </tr> </table> <h1 style="color: red; text-align: center">添加成功</h1> </form> </body> </html>
findup.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>查询</title> </head> <body> <form action="update.jsp" method="post" target="_self"> <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10" style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500"> <tr> <td>请输入要查询的计划编号</td> <td><input type="text" placeholder="请输入查询内容" name="key"></td> </tr> <tr> <th colspan=2><input type="submit" value="查询"></th> </tr> </table> </form> </body> </html>
update.jsp
<%@ page import="java.sql.DriverManager" %> <%@ page import="java.sql.Connection" %> <%@ page import="java.sql.Statement" %> <%@ page import="java.sql.ResultSet" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>修改生产计划</title> </head> <body> <% String name=request.getParameter("name"); String talk=request.getParameter("talk"); String way=request.getParameter("way"); String otime=request.getParameter("opentime"); String ctime=request.getParameter("closetime"); String tech=request.getParameter("tech"); pageContext.setAttribute("s1",name); pageContext.setAttribute("s2",talk); pageContext.setAttribute("s3",way); pageContext.setAttribute("s4",otime); pageContext.setAttribute("s5",ctime); pageContext.setAttribute("s6",tech); %> <form action="updatefinish.jsp" method="post" target="_self"> <table bgcolor="yellow" border="5" cellpadding="10" cellspacing="10" style="margin: 10px auto; color: darkorange; border-collapse: collapse" align="center" width="500"> <tr> <th colspan=2>查询结果</th> </tr> <% String key=request.getParameter("key"); //1.注册驱动 Class.forName("com.mysql.cj.jdbc.Driver"); // 2.使用我自己的数据库 test 获取链接 String url = "jdbc:mysql://localhost:3306/test"; String username = "root"; String password = "123456"; Connection connection = DriverManager.getConnection(url, username, password); //获取执行sql的对象statement Statement statement = connection.createStatement(); String sql="select * from plan where 计划编号 = '"+key+"'"; ResultSet res=statement.executeQuery(sql); int flag=0; pageContext.setAttribute("p",key); while(res.next()){ String s1=res.getString("计划名称"); String s2=res.getString("计划概述"); String s3=res.getString("排产方式"); String s4=res.getString("开始时间"); String s5=res.getString("结束时间"); String s6=res.getString("包含工艺"); pageContext.setAttribute("p1",s1); pageContext.setAttribute("p2",s2); pageContext.setAttribute("p3",s3); pageContext.setAttribute("p4",s4); pageContext.setAttribute("p5",s5); pageContext.setAttribute("p6",s6); flag++; %> <input type="hidden" name="key" value="${p}"> <tr> <td>计划名称:</td> <td><input type="text" name="name" value="${p1}"></td> </tr> <tr> <td>计划概述:</td> <td><input type="text" name="talk" value="${p2}"></td> </tr> <tr> <td>排产方式:</td> <td><input type="text" name="way" value="${p3}"></td> </tr> <tr> <td>开始时间:</td> <td><input type="text" name="otime" value="${p4}"></td> </tr> <tr> <td>结束时间:</td> <td><input type="text" name="ctime" value="${p5}"></td> </tr> <tr> <td>包含工艺:</td> <td><input type="text" name="tech" value="${p6}"></td> </tr> <% } if(flag==0){ %> <tr> <th colspan=6>该生产计划不存在</th> </tr> <form action="index1.jsp" target="_self"> <tr> <th colspan=2><input type="submit" value="返回首页"></th> </tr> </form> <% } %> <tr> <th colspan=2><input type="submit" value="修改"></th> </tr> </table> </form> </body> </html>
updatefinish.jsp
<%@ page import="java.sql.*" %><%-- Created by IntelliJ IDEA. User: 惠普 Date: 2023/10/29 Time: 11:35 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>修改成功</title> </head> <h1 style="color: red; text-align: center">修改成功</h1> <% String key=request.getParameter("key"); String name=request.getParameter("name"); String talk=request.getParameter("talk"); String way=request.getParameter("way"); String otime=request.getParameter("otime"); String ctime=request.getParameter("ctime"); String tech=request.getParameter("tech"); try{ Class.forName("com.mysql.cj.jdbc.Driver"); // 2.使用我自己的数据库 test 获取链接 String url = "jdbc:mysql://localhost:3306/test"; String username = "root"; String password = "123456"; Connection connection = DriverManager.getConnection(url, username, password); //获取执行sql的对象statement Statement statement = connection.createStatement(); String sql="update plan set 计划名称 = '"+name+"' ,计划概述 = '"+talk+"' ,排产方式 = '"+way+"' ,开始时间 = '"+otime+"' ,结束时间 = '"+ctime+"' ,包含工艺 = '"+tech+"' where 计划编号 = '"+key+"'"; PreparedStatement ps1=connection.prepareStatement(sql); ps1.executeUpdate(); ps1.close(); connection.close(); }catch(Exception e){ System.out.println(e); } %> <body> <form action="index1.jsp" method="post" target="_self"> <table> <tr> <th colspan=7><input type="submit" value="返回首页"></th> </tr> </table> </form> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!