第一个PSP0级

 1.计划:

需求描述:

按照图片要求设计添加新课程界面。(0.5分)

在后台数据库中建立相应的表结构存储课程信息。(0.5分)

实现新课程添加的功能。 要求判断任课教师为王建民、刘立嘉、刘丹、王辉、杨子光五位教师的其中一位。(0.5分)

要求上课地点开头为“一教、二教、三教、基教”中的一种。(0.5分)

实现数据存储功能。(3分)

 估计开发时间:2个小时;

 填写的项目数据:

课堂名称;

课堂老师;

课堂地点;

 填写时间记录日志:

上午9:10-9:50        进行题目的解析,制定解题思路,进行编码;

上午13:10-13:30     设计判断输入的是否符合要求;

上午13-30-14:10       解决问题中的缺陷,问题,不足;

2.

程序设计思想:

   在login.jsp中创建一个登录界面里包括课程名称,任课老师,教学地点,设置三个文本框来接受输入的三个属性,

并传到另外的logininput.jsp页面中,又来接受三个数据,并判断传来的教师,与教室地点是否符合题目要求,若不符合,则设置

一个error,返回到第一个login.jsp中,并接受和输出到login.jsp界面,允许重新输入,若符合要求,就保存到数据库,实现1课表的添加。

源代码:

package com.jaovo.msg.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 {
//1 鍔犺浇椹卞姩
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String user = "root";
String password = "";
String url = "jdbc:mysql://localhost:3306/jaovo_msg";
Connection connection = null;
try {
//2 鍒涘缓閾炬帴瀵硅薄connection
connection = DriverManager.getConnection(url,user,password);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return connection;
}

//鍏抽棴璧勬簮鐨勬柟娉?
public static void close(Connection connection ) {
try {
if (connection != null) {
connection.close();
}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void close(PreparedStatement preparedStatement ) {
try {
if (preparedStatement != null) {
preparedStatement.close();
}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void close(ResultSet resultSet ) {
try {
if (resultSet != null) {
resultSet.close();
}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

package com.jaovo.msg.dao;

import java.util.List;

import com.jaovo.msg.model.User;

public interface IUserDao {
public void add(User user);
}

package com.jaovo.msg.model;

public class User {
private String classname;
private String teachername;
private String point;
public String getClassname() {
return classname;
}
public void setClassname(String classname) {
this.classname = classname;
}
public String getTeachername() {
return teachername;
}
public void setTeachername(String teachername) {
this.teachername = teachername;
}
public String getPoint() {
return point;
}
public void setPoint(String point) {
this.point = point;
}
}

package com.jaovo.msg.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;


import com.jaovo.msg.Util.DBUtil;
import com.jaovo.msg.Util.UserException;
import com.jaovo.msg.model.User;

import sun.net.www.content.text.plain;

public class UserDaoImpl implements IUserDao {

@Override
public void add(User user) {
//获得链接对象
Connection connection = DBUtil.getConnection();
PreparedStatement preparedStatement = null;
try
{
String sql = "insert into t_teacher(classname,teachername,point) value (?,?,?)";
preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, user.getClassname());
preparedStatement.setString(2, user.getTeachername());
preparedStatement.setString(3, user.getPoint());
preparedStatement.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
//关闭资源
//DBUtil.close(resultSet);
DBUtil.close(preparedStatement);
DBUtil.close(connection);
}
}
}

<%@ 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>Insert title here</title>
</head>
<body>
<%
String loginError = (String)request.getAttribute("loginError");
if(loginError == null){
loginError = "";
}
%>
<%=loginError %><br>
<form action="logininput.jsp" method="get">
课程名称 : <input type="text" name="classname" /><br>
任课教师 : <input type="text" name="teachername" /><br>
上课地点: <input type="text" name="point" /><br>
<input type="submit" value="用户登录" />
</form>
</body>
</html>

<%@page import="com.jaovo.msg.dao.UserDaoImpl"%>
<%@page import="com.jaovo.msg.Util.UserException"%>
<%@page import="com.jaovo.msg.model.User"%>
<%@page import="com.jaovo.msg.Util.DaoFactory"%>
<%@page import="com.jaovo.msg.dao.IUserDao"%>
<%@ 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>
<%
String classname=request.getParameter("classname");
String teachername=request.getParameter("teachername");
String point=request.getParameter("point");
if(classname==null||"".equals(classname.trim()))
{
request.setAttribute("error", "课程名称不能为空!");
%>
<jsp:forward page="login.jsp"></jsp:forward>
<%
}
if(teachername==null||"".equals(teachername.trim()))
{
request.setAttribute("error", "任课教师不能为空!");
%>
<jsp:forward page="login.jsp"></jsp:forward>
<%
}
if(point==null||"".equals(point.trim()))
{
request.setAttribute("error", "上课地点不能为空!");
%>
<jsp:forward page="login.jsp"></jsp:forward>
<%
}
if(!teachername.trim().equals("王建民")&&!teachername.trim().equals("刘丹")
&&!teachername.trim().equals("刘立嘉")&&!teachername.trim().equals("王辉")
&&!teachername.trim().equals("杨子光"))
{
request.setAttribute("error", "老师不存在");
%>
<jsp:forward page="login.jsp"></jsp:forward>
<%
}
if(!point.trim().substring(0,2).equals("基教")
&&!point.trim().substring(0,2).equals("一教")
&&!point.trim().substring(0,2).equals("二教")
&&!point.trim().substring(0,2).equals("三教"))
{
request.setAttribute("error", "上课地点不存在!");
%>
<jsp:forward page="login.jsp"></jsp:forward>
<%
}
User user=new User();
user.setClassname(classname);
user.setTeachername(teachername);
user.setPoint(point); 
UserDaoImpl UserDao=new UserDaoImpl();
UserDao.add(user);
%>
<h2 style="color:pink" align="center">课程信息保存成功</h2>
<form>
<table align="center" border="2" width="100">
<tr align="center">
<td colspan="2">
<a href="kechengjiemian.jsp"><u>继续添加</u></a>
</td>
</tr>
</table>
</form>
<%
%>
</html>

结果截图:

编译程序,修复并记录所发现的缺陷,并填写缺陷记录日志

在编译程序中,出现的变异问题是向数据库中存储数据时,出现中文乱码。

修复:将jsp界面、文件编码。数据库编码保持一致为UTF-8.

学生:孙丙海

日期:2017.11.28

教师:王建民

程序号:1

日期

编号

类型

引入阶段

排除阶段

修复时间

修复缺陷

11/28

1

20

编码

编译

20min

将jsp界面、文件编码。数据库编码保持一致为UTF-8.

测试程序,修复并记录所出现的缺陷,并填写缺陷记录日志:

学生:孙丙海

日期:2017.11.28

教师:王建民

程序号:2

日期

编号

类型

引入阶段

排除阶段

修复时间

修复缺陷

11/28

2

20

编码

编译

5min

在jsp界面跳转中注意大小写问题,例如Input与input.

原文地址:https://www.cnblogs.com/xiaohaigege666/p/7912215.html