课程 教师 教室
- 设计思想
定义三个信息,连接数据库,输入用户信息。
- 源程序代码截图


package bean;
public class Ms {
String classname;
String place;
String teacher;
public String getClassname() {
return classname;
}
public void setClassname(String classname) {
this.classname = classname;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
}View Codepackage dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import bean.Ms;
import util.DButil;
public class classMs {
public void add(Ms ms)
{
//获得链接对象
Connection connection = DButil.getConnection();
//创建语句传输对象
PreparedStatement preparedStatement = null;
try {
String sql = "insert into kc_msg (classname,teacher,place) value (?,?,?)";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, ms.getClassname());
preparedStatement.setString(2,ms.getTeacher());
preparedStatement.setString(3,ms.getPlace());
preparedStatement.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
//关闭资源
DButil.close(connection);
}
}
}

package util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DButil {
public static Connection getConnection()
{
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
String user="root";
String password="root";
String url = "jdbc:mysql://localhost:3306/jaovo_msg";
Connection connection=null;
try {
connection=DriverManager.getConnection(url,user,password);
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return connection;
}
public static void close(Connection connection)
{
try {
connection.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
public static void close(PreparedStatement preparedStatement)
{
try {
preparedStatement.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
public static void close(ResultSet resultSet)
{
try {
resultSet.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
package util;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
public class Exception {
public static boolean validateNull(HttpServletRequest request,String[] fileds) {
boolean validate = true;
//map对象用来装载不同的错误信息
Map<String,String> errorMsg = new HashMap();
for(String filed :fileds) {
String value = request.getParameter(filed);
if (value == null || "".equals(value.trim())) {
validate = false;
errorMsg.put(filed, "不能为空!");
}
if (!validate) {
request.setAttribute("errormsg", errorMsg);
}
}
return validate;
}
public static String showError(HttpServletRequest request , String filed) {
Map<String, String> errorMsg = (Map<String,String>)request.getAttribute("errormsg");
if (errorMsg == null) {
return "";
}
String msg = errorMsg.get(filed);
if (msg == null) {
return "";
}
return msg;
}
}View Code

<%@page import="java.util.Map"%>
<%@page import="util.Exception"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加课程</title>
</head>
<body>
<%Map<String,String> errorMs = (Map<String,String>)request.getAttribute("errorms");
%>
<form action="saveInput.jsp" method="get">
<br>
<center > 课程名称:<input type="text" name="classname" /><%= Exception.showError(request, "classname") %></center>
<br>
<center > 任课教师:<input type="text" name="teacher" /><%= Exception.showError(request, "teacher") %></center>
<br>
<center > 上课地点:<input type="text" name="place" /><%= Exception.showError(request, "place") %></center>
<br>
<center><input type="submit" value="保存" /> </center>
</form>
</body>
</html>View Code

<%@page import="util.Exception"%>
<%@page import="bean.Ms"%>
<%@page import="dao.classMs"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加课程</title>
</head>
<body>
<%
//接收客户端传递过来的参数
String classname = request.getParameter("classname");
String teacher = request.getParameter("teacher");
String place = request.getParameter("place");
boolean validate = Exception.validateNull(request, new String[]{"classname","teacher","place"});
if(!validate){
%>
<jsp:forward page="save.jsp"></jsp:forward>
<%
}
if(!place.startsWith("基教")&&!place.startsWith("一教")&&!place.startsWith("二教")&&!place.startsWith("三教"))
{
%>
<script language='javaScript' > alert('没有这个教室\n请重新输入!');window.history.back(-1);</script>
<%
}
else if(!teacher.equals("王建民")&&!teacher.equals("刘立嘉")&&!teacher.equals("刘丹"))
{
%>
<script language='javaScript' > alert('没有这个老师!\n请重新输入');window.history.back(-1);</script>
<%
}
else
{
Ms msg=new Ms();
msg.setClassname(classname);
msg.setTeacher(teacher);
msg.setPlace(place);
classMs cm=new classMs();
cm.add(msg);
}
%>
<center>保存成功!!<br></center>
<center><a href="save.jsp">继续添加</a></center>
</body>
</html>View Code- 项目计划日历
时间 | 课堂测试 | 编写程序 | 总计 |
上午 | 50分钟 | 50分钟 | |
下午 | 2个小时 | 120分钟 |
时间记录日历
日期 | 开始时间 | 中断时间 | 净时间 | 活动 | 备注 |
11.28 | |||||
上午 | 9:00 | 9:50 | 50 | 编程 | 课堂测试 |
下午 | 1:00 | 3:00 | 120 | 编程 | 编程 |
缺陷记录日志
日期 | 编号 | 类型 | 引入阶段 | 排除阶段 | 修复时间 | 修复缺陷 |
11.28 | 1 | 5分钟 | ||||
描述:无法传入数据库。 | ||||||
2 | 10分钟 | |||||
描述:界面跳转不正确。 | ||||||
相关推荐
Lzs 2020-10-23
聚合室 2020-11-16
零 2020-09-18
Justhavefun 2020-10-22
ChaITSimpleLove 2020-10-06
周游列国之仕子 2020-09-15
afanti 2020-09-16
88234852 2020-09-15
YClimb 2020-09-15
风雨断肠人 2020-09-04
卖口粥湛蓝的天空 2020-09-15
stulen 2020-09-15
pythonxuexi 2020-09-06
abfdada 2020-08-26
梦的天空 2020-08-25