|
@@ -16,27 +16,34 @@ public class MMC_01 extends HttpServlet
|
|
|
{
|
|
|
|
|
|
|
|
|
- public static final String DBURL = "jdbc:mysql://localhost:3306/kui";
|
|
|
- // 连接数据库的用户名
|
|
|
- public static final String DBUSER = "root";
|
|
|
- // 连接数据库的密码
|
|
|
- public static final String DBPASS = "001011";
|
|
|
+ public static final String DBURL = "jdbc:mysql://localhost:3306/kui";
|
|
|
+ // 连接数据库的用户名
|
|
|
+ public static final String DBUSER = "root";
|
|
|
+ // 连接数据库的密码
|
|
|
+ public static final String DBPASS = "001011";
|
|
|
|
|
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
throws ServletException, IOException
|
|
|
{
|
|
|
//设置请求和响应的编码 ,不然页面上容易出现乱码
|
|
|
request.setCharacterEncoding("UTF-8");
|
|
|
- response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+
|
|
|
response.setContentType("text/html;UTF-8");
|
|
|
//输出流
|
|
|
PrintWriter out = response.getWriter();
|
|
|
//数据库连接代码
|
|
|
try
|
|
|
{
|
|
|
+
|
|
|
+ out.print("<form method=\"get\" action=\"http://localhost:8080/devicemanagement/onlyCheck\" align=\"center\">\r\n" +
|
|
|
+ "设备名称:<input type=\"text\" name=\"name\" ><br><br>\r\n" +
|
|
|
+ "<input type=\"submit\" value=\"提交\" class=\"sub\">"+
|
|
|
+
|
|
|
+ "<table align=\"center\">");
|
|
|
Connection conn = null; // 表示数据库的连接的对象
|
|
|
Statement stmt = null; // 表示数据库的更新操作
|
|
|
- String sql="insert into student(name,calssGrent,result) values('PS4','2333',' 2998')";
|
|
|
+ String sql="insert into student(name,calssGrent,result) values('PS的4','3的3',' 发98')";
|
|
|
System.out.println(sql) ;
|
|
|
// 1、使用Class类加载驱动程序
|
|
|
Class.forName("com.mysql.jdbc.Driver");
|
|
@@ -47,12 +54,85 @@ public class MMC_01 extends HttpServlet
|
|
|
|
|
|
ResultSet rs=stmt.executeQuery("select *from student");
|
|
|
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
|
|
|
- out.println("<HTML>");
|
|
|
+ out.println("<HTML>");
|
|
|
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
|
|
|
+ out.print("<style type=\"text/css\">");
|
|
|
+ out.print("body{\r\n" +
|
|
|
+ " background-color: skyblue;\r\n" +
|
|
|
+ " }");
|
|
|
+ out.print("body{\r\n" +
|
|
|
+ " background-color: #EECED9;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " h1{\r\n" +
|
|
|
+ " text-align: center;\r\n" +
|
|
|
+ " color:#CD05F7;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " table{\r\n" +
|
|
|
+ " width: 400px;\r\n" +
|
|
|
+ " height: 80px;\r\n" +
|
|
|
+ " text-align: center;\r\n" +
|
|
|
+ " border: none;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " td{\r\n" +
|
|
|
+ " border-radius: 20px;\r\n" +
|
|
|
+ " border:1.3px solid skyblue;\r\n" +
|
|
|
+ " color:#A71E1E;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " td:hover{\r\n" +
|
|
|
+ " background-color: skyblue;\r\n" +
|
|
|
+ " font-size: 17px;\r\n" +
|
|
|
+ " }");
|
|
|
+ out.print("h1{\r\n" +
|
|
|
+ " font-size: 28px;\r\n" +
|
|
|
+ " text-align: center;\r\n" +
|
|
|
+ " color:#A75480;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " @keyframes move{\r\n" +
|
|
|
+ " 0%{\r\n" +
|
|
|
+ " color:pink;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " 20%{\r\n" +
|
|
|
+ " color:skyblue;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " 40%{\r\n" +
|
|
|
+ " color:red;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " 60%{\r\n" +
|
|
|
+ " color:blue;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " 80%{\r\n" +
|
|
|
+ " color:green;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " 90%{\r\n" +
|
|
|
+ " color:gold;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ "\r\n" +
|
|
|
+ " h1{\r\n" +
|
|
|
+ " animation-name: move;\r\n" +
|
|
|
+ " animation-duration: 30s;\r\n" +
|
|
|
+ " }");
|
|
|
+ out.print(" .main{\r\n" +
|
|
|
+ " border-radius: 20px;\r\n" +
|
|
|
+ " width: 150px;\r\n" +
|
|
|
+ " height: 40px;\r\n" +
|
|
|
+ " text-align: center;\r\n" +
|
|
|
+ " font-size: 28px;\r\n" +
|
|
|
+ " text-decoration: none;\r\n" +
|
|
|
+ " border: solid;\r\n" +
|
|
|
+ " display: block;\r\n" +
|
|
|
+ " position: absolute;\r\n" +
|
|
|
+ " top: 85%;\r\n" +
|
|
|
+ " right: 8%;\r\n" +
|
|
|
+ " }\r\n" +
|
|
|
+ " .main:hover{\r\n" +
|
|
|
+ " background-color: skyblue;\r\n" +
|
|
|
+ " }");
|
|
|
+
|
|
|
+ out.print("</style>");
|
|
|
out.println(" <BODY>");
|
|
|
- out.println(" <center><font size='14px'> 设备管理系统");
|
|
|
- out.println("</font> </center>");
|
|
|
//输出表头部分
|
|
|
+ out.print("<h1>设备管理系统</h1>");
|
|
|
out.print("<table align='center' border='1'><tr><td>设备名称" +
|
|
|
"</td><td>数量</td><td>价格</td><td>修改</td><td>删除</td></tr>");
|
|
|
while(rs.next())
|
|
@@ -69,6 +149,7 @@ public class MMC_01 extends HttpServlet
|
|
|
|
|
|
}
|
|
|
out.println("<td><a href=AddPage>添加数据</a></td>");
|
|
|
+ out.print("<a href=\"test2.html\" class=\"main\">返回主页</a>");
|
|
|
out.println(" </BODY>");
|
|
|
out.println("</HTML>");
|
|
|
conn.close();
|