软件工程概论
1、设计思想
在mysql中建立一个数据库,并在其中建立相应的表。建立一个类,将表中的基本属性设为该类的私有成员变量,编写连接数据库的方法,向表中插入数据(即添加课程信息)。编写一个方法,
其可判断输入的信息与表中的信息是否相等来完成对课程信息的查询,创建相应的jsp或html文件,完成相应的界面跳转与显示。
2、源程序
package bean;
public class Userbean {
private String coursename;
private String teacher;
private String local;
public String getcoursename() {
return coursename;
}
public void setcoursename(String username) {
this.coursename = username;
}
public String getteacher() {
return teacher;
}
public void setteacher(String teacher) {
this.teacher = teacher;
}
public String getlocal() {
return local;
}
public void setlocal(String local) {
this.local = local;
}
}
package dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import DUBtil.DBUtil;
import bean.Userbean;
public class Userdao {
public boolean register(Userbean userbean)
{
boolean flag=false;
Connection conn=DBUtil.getConn();
Statement state=null; //Statement对象,用于执行不带参数的简单SQL语句
String sql="insert into course(coursename,teacher,local) values('"+userbean.getcoursename()+"','"+userbean.getteacher()+"','"+userbean.getlocal()+"')";
try
{
state=conn.createStatement();
state.executeUpdate(sql);
flag=true;
}
catch(Exception e)
{
e.printStackTrace();
flag=false;
}
finally
{
DBUtil.close(state,conn);
}
return flag;
}
public boolean Checklogin(String coursename,String teacher)
{
boolean flag=false;
Connection conn=DBUtil.getConn();
Statement state=null;
ResultSet rs=null; //ResultSet是数据库结果集的数据表
try
{
state=conn.createStatement();
rs=state.executeQuery("select * from course where coursename='"+coursename+"'");
if(rs.next())
{
if(rs.getString("teacher").equals(teacher))
{
flag=true;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
DBUtil.close(rs,state,conn);
}
return flag;
}
}
package DUBtil;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil
{
public static String db_url="jdbc:mysql://localhost:3306/Lvyouba?uerUnicode=true&characterEncoding=UTF-8";
public static String db_user="root";
public static String db_password="root";
public static Connection getConn()
{
Connection conn=null;
try
{
Class.forName("com.mysql.jdbc.Driver"); //加载数据库驱动
conn=DriverManager.getConnection(db_url,db_user,db_password);
}
catch(Exception e)
{
e.printStackTrace();
}
return conn;
}
public static void close(Statement state,Connection conn)//关闭
{
if(state!=null)//判断
{
try
{
state.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
public static void close(ResultSet rs,Statement state,Connection conn)
{
if(rs!=null)
{
try
{
rs.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
if(state!=null)
{
try
{
state.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}
package servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class BaseServlet extends HttpServlet {
private static final long serialVersionUID = -7039609732089204655L;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
// TODO Auto-generated method stub
try {
String method=request.getParameter("method");
Method m=this.getClass().getMethod(method, HttpServletRequest.class,HttpServletResponse.class);
m.invoke(this, request,response);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import dao.Userdao;
import bean.Userbean;
public class UserServlet extends BaseServlet {
public void Login(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
PrintWriter out=response.getWriter();
String coursename=request.getParameter("coursename");
String teacher=request.getParameter("teacher");
Userdao userbean=new Userdao();
if(userbean.Checklogin(coursename, teacher))
{
request.getSession().setAttribute("coursename", coursename);
response.sendRedirect(request.getContextPath() + "/index.jsp");
//response.sendRedirect:地址重定向(页面跳转)
//request.getRequestDispatcher("/index.jsp").forward(request, response);
}
else
{
response.sendRedirect(request.getContextPath() + "/loginfail.html");
}
}
public void Register(HttpServletRequest request,HttpServletResponse response) throws IOException
{
PrintWriter out=response.getWriter();
String coursename=request.getParameter("coursename");
String teacher=request.getParameter("teacher");
String local=request.getParameter("local");
Userbean userbean=new Userbean();
userbean.setcoursename(coursename);
userbean.setteacher(teacher);
userbean.setlocal(local);
Userdao userdao=new Userdao();
boolean i=userdao.register(userbean);
if(i)
{
response.sendRedirect(request.getContextPath() + "/registersuc.html");
}
else
{
out.print("<script>alert('注册失败!')</script>");
response.sendRedirect(request.getContextPath() + "/register.html");
}
}
public void show(HttpServletRequest request,HttpServletResponse response) throws IOException
{
PrintWriter out= response.getWriter();
String coursename=request.getParameter("coursename");
String teacher=request.getParameter("teacher");
out.print("<script>alert('"+coursename+"')</script>");
out.print("<script>alert('"+teacher+"')</script>");
}
}
Index.jsp
<%@ 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>
<h1>登录成功</h1>
</body>
</html>
Login.html
<!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>
<center>
<h1>登录界面</h1>
<form id="loginform" method="post" action="servlet/UserServlet?method=Login">
课程:<input type="text" name="coursename" size="20" required/><br>
教师:<input type="text" name="teacher" size="20" required /><br>
地点:<input type="text" name="local" size="20" required/><br>
<input type="submit" value="登录" size="20">
<input type="button" value="注册" size="20" onclick="javascript:window.location.href='register.html'">
</form>
</center>
</body>
</html>
Loginfail.html
<!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>
登录失败
</body>
</html>
Register.html
<!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>
<center>
<h1>注册页面</h1>
<form id="registerform" action="servlet/UserServlet?method=Register" method="post">
课程:<input type="text" id="t1" name="coursename" required/><br>
老师:<input type="text" name="teacher" required/><br>
地点:<input type="text" name="local" required/><br>
<input type="button" onClick="registerform.submit()" value="提交"/>
</form>
</center>
</body>
</html>
Registsuc.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style type="text/css">
.tishi {
font-family: "仿宋";
font-size: 26px;
color:#f89521;
}
</style>
<title>JavaScript控制页面5秒后自动跳转的代码</title>
<script type="text/javascript">
function countDown(secs,surl){
var jumpTo = document.getElementById('jumpTo');
jumpTo.innerHTML=secs;
if(--secs>0){
setTimeout("countDown("+secs+",'"+surl+"')",1000);
}
else
{
location.href=surl;
}
}
</script>
</head>
<body><a class="tishi">注册成功</a><span id="jumpTo" class="tishi">3</span><a class="tishi">秒后自动跳转到登陆页面</a>
<script type="text/javascript">
countDown(3,'login.html');
</script>
</body>
</html>
3、截图
周活动总结表
姓名:王云玲 日期:28/11/2017
任务
日期 |
听课 |
编写程序 |
阅读课本 |
准备考试 |
日总计 |
周一 |
|
|
|
|
|
周二 |
40 |
130 |
20 |
180 |
370 |
周三 |
|
|
|
|
|
周四 |
|
|
|
|
|
周五 |
|
|
|
|
|
周六 |
|
|
|
|
|
周日 |
|
|
|
|
|
周总计 |
|
|
|
|
|
时间记录日志
学生: 王云玲 日期:28/11/2017
教师: 王建民 课程:软件工程概论
日期 |
开始 时间 |
结束 时间 |
中断时间 |
净时间 |
活动 |
备注 |
C |
U |
28/11 |
8.00 |
10.00 |
10 |
100 |
上课 |
上课 |
|
|
|
1.30 |
3.30 |
|
120 |
敲代码 |
课堂测试 |
|
|
|
4.30 |
6.00 |
|
90 |
编程序&写报告 |
完善程序 |
|
|
|
8.00 |
10.00 |
|
120 |
看书 |
考试准备 |
|
|
缺陷记录日志
学生 : 王云玲
日期 : 28/11/2017
教员 :王建民
日期 |
编号 |
类型 |
引入阶段 |
排除阶段 |
修复阶段 |
修复缺陷 |
28/11 |
1 |
40 |
设计 |
编译 |
3min |
|
描述:出现404错误,原因为未添加web.xml文件 |
||||||
|
2 |
20 |
编码 |
编译 |
3min |
|
描述:改了实体类的代码,未重启服务器,得不到响应。 |
作业号 |
日期 |
过程 |
估计数据 |
实际数据 |
累计数据 |
|||||||
|
时间 |
单元 |
时间 |
单元 |
平均值 |
时间 |
单元 |
平均值 |
最大值 |
最小值 |
||
1 |
28/11 |
编写程序 |
150 |
1 |
230 |
1 |
230 |
230 |
1 |
230 |
2 3 0 |
200 |