1 概述
系统设计是一个把软件需求转换成用软件系统表示的过程[9]。通过对目标系统的分析和研究,做出了教学通知助手网站的总体规划,这是全面开发系统的重要基础。在对教学通知助手网站全面分析调查的基础上,制定出教学通知助手网站的总体规划。系统设计包括系统总体设计、系统详细设计、系统数据库设计、系统开发工具、开发技术和开发模式等。
从数据流图出发,对数据流图进行分析,得出的层次化的模块结构图.
教学通知助手网站前台功能模块图如图4.1所示:
2 数据库表
t_doc 通知内容表 | ||
名称 | 类型 | 说明 |
id | int(11) | 编号 |
title | text | 标题 |
content | text | 内容 |
fujian | text | 附件 |
fujianYuanshiming | text | 附件名称 |
shijian | text | 时间 |
fenlei | text | 类型 |
stu_id | int(11) | 学生ID |
t_gonggao 公告内容表 | ||
名称 | 类型 | 说明 |
id | int(11) | 编号 |
title | longtext | 标题 |
content | longtext | 内容 |
shijian | longtext | 时间 |
3 关键代码
package com.action;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.DB;
import com.orm.TAdmin;
import com.orm.Tgonggao;
//import com.orm.Tuser;
public class gonggao_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("gonggaoAdd"))
{
gonggaoAdd(req, res);
}
if(type.endsWith("gonggaoMana"))
{
gonggaoMana(req, res);
}
if(type.endsWith("gonggaoDel"))
{
gonggaoDel(req, res);
}
if(type.endsWith("gonggaoDetail"))
{
gonggaoDetail(req, res);
}
if(type.endsWith("gonggaoDetailQian"))
{
gonggaoDetailQian(req, res);
}
}
public void gonggaoAdd(HttpServletRequest req,HttpServletResponse res)
{
//String id=String.valueOf(new Date().getTime());
String title=req.getParameter("title");
String content=req.getParameter("content");
String shijian=new Date().toLocaleString();
String sql="insert into t_gonggao values(?,?,?,?)";
Object[] params={null,title,content,shijian};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "gonggao?type=gonggaoMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void gonggaoDel(HttpServletRequest req,HttpServletResponse res)
{
String id=req.getParameter("id");
String sql="delete from t_gonggao where id=?";
Object[] params={id};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "操作成功");
req.setAttribute("path", "gonggao?type=gonggaoMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void gonggaoMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
List gonggaoList=new ArrayList();
String sql="select * from t_gonggao";
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
while(rs.next())
{
Tgonggao gonggao=new Tgonggao();
gonggao.setId(rs.getString("id"));
gonggao.setTitle(rs.getString("title"));
gonggao.setContent(rs.getString("content"));
gonggao.setShijian(rs.getString("shijian"));
gonggaoList.add(gonggao);
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("gonggaoList", gonggaoList);
req.getRequestDispatcher("admin/gonggao/gonggaoMana.jsp").forward(req, res);
}
public void gonggaoDetail(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String id=req.getParameter("id");
Tgonggao gonggao=new Tgonggao();
String sql="select * from t_gonggao where id=?";
Object[] params={id};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
rs.next();
gonggao.setId(rs.getString("id"));
gonggao.setTitle(rs.getString("title"));
gonggao.setContent(rs.getString("content"));
gonggao.setShijian(rs.getString("shijian"));
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("gonggao", gonggao);
req.getRequestDispatcher("admin/gonggao/gonggaoDetail.jsp").forward(req, res);
}
public void gonggaoDetailQian(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String id=req.getParameter("id");
Tgonggao gonggao=new Tgonggao();
String sql="select * from t_gonggao where id=?";
Object[] params={id};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
rs.next();
gonggao.setId(rs.getString("id"));
gonggao.setTitle(rs.getString("title"));
gonggao.setContent(rs.getString("content"));
gonggao.setShijian(rs.getString("shijian"));
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
req.setAttribute("gonggao", gonggao);
req.getRequestDispatcher("/qiantai/gonggao/gonggaoDetailQian.jsp").forward(req, res);
}
public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
{
RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
try
{
dispatch.forward(request, response);
return;
}
catch (ServletException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void destroy()
{
}
}
4 效果演示
idea或eclipse开发,mysql数据库