pstmt.setString(2,note_content);
pstmt.setString(3,note_time);
int n=pstmt.executeUpdate();
if(n==1){
return true;
} else {
return false;
}
}catch(SQLException e){
e.printStackTrace();
throw e;
}finally{
DBconn.closePstmt(pstmt);
DBconn.closeConn(conn);
}
}
学生的主页是由主页中include进去几个页组成的。所以要在用户的页面中显示公告,创建了一个Head_MainAction类,在该类中的show方法中使用 request.getSession().setAttribute("list_note", list_note);将list_note放在session中的。于是只要浏览器不关,在任何一个显示页面都能取到用EL表达${lsit_note}取得。
6.2.5 留言管理模块
在教师的留言管理模块中,教师可以回复留言和删除留言。学生只可以查看留言和留言。教师用户创建了一个Back_MessageAction类,调用MessageManager中的诸方法来添加或删除留言。学生用户创建了一个Head_MessageAction类,调用MessageManager中某些方法。在学生显示留言页面要分我利用了jstl加EL表达式分页,关键代码如下:
MessageActionForm maf = (MessageActionForm)form;
MessageManager mm = new MessageManager();
ArrayList list = mm.query();
int pageSize = list.size() / 4 + 1;
ArrayList list1 = new ArrayList();
int begin = 0;
int end = 3;
int currentPage = 1;
//---从页面得到数据---
if(maf.getCurrentPage()!=1&&maf.getCurrentPage()!=0)
{
begin = maf.getBegin();
end = maf.getEnd();
currentPage = maf.getCurrentPage();
}
maf.setBegin(begin);
maf.setEnd(end);
maf.setCurrentPage(currentPage);
list1.add(maf);
request.setAttribute("currentTime", new Date());
request.setAttribute("list", list);
request.setAttribute("list1", list1);
request.setAttribute("pageSize", Integer.valueOf(pageSize));
return mapping.findForward("showmessage");
6.2.6 视频管理模块
视频管理模块分为学生用户主页的视频管理和教师用户主页的视频管理。教师成功登录后,在教师用户的主页中的视频管理模块,教师可以上传新的视频,也可以删除以前传过的视频。点击“上传视频”就会进入到电子教案上传的页面,教师点击“浏览”选择要上传的视频,然后点上传就完成了一个视频的上传。上传视频的关键代码如下:
UpLoadForm uploadFile = (UpLoadForm)
form;
FormFile file = uploadFile.getFile();
String uuidName = UUID.randomUUID().toString();
String video_Name = uuidName+file.getFileName();
String video_Time = uploadFile.getVideo_Time();
System.out.println("时间="+video_Time);
ServletContext servletContext = this.getServlet().getServletContext();
String path = servletContext.getRealPath("");
FileOutputStream out = new FileOutputStream(path+"/uploadV/"+video_Name);
out.write(file.getFileData());
out.flush();
out.close();
UpLoadManager ulm = new UpLoadManager();
boolean flag = ulm.videoAdd(video_Name, video_Time);
if(flag){
request.setAttribute("currentTime", new Date());
request.setAttribute("upload", "success");
return mapping.findForward("upload");
}
request.setAttribute("upload", "fail");
return mapping.findForward("AuploadV");
path表示得到当前项目下webRoot 的路径,为了保存视频,在webRoot下建立了一个名为uploadV的文件夹,把视频保存在tomcat服务器下。同时为避免出现相同文件名的视频名字,每个视频上传之前在视频名前加了一段唯一的UUID字符编码,对应数据可存入tb_video表中的video_Name字段,将来在显示视频的详细信息时同样根据video_Name来寻找视频。
学生下载视频,用video_Name查找下载视频。下载视频的代码如下:
UpLoadForm ulf = (UpLoadForm)form;
String video_Name = ulf.getVideo_Name();
video_Name = new String(video_Name.getBytes("ISO-8859-1"),"GB18030");
ServletContext servletContext = this.getServlet().getServletContext();
String path = servletContext.getRealPath("");
FileInputStream inPut = new FileInputStream(path+"/uploadV/"+video_Name);
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + new String(video_Name.getBytes("GB18030"),"ISO-8859-1"));
OutputStream out = response.getOutputStream();
byte[] b = new byte[1024*1024];
while(inPut.read(b)>0){
out.write(b);
out.flush();
}
inPut.close();
out.close();
教师可以根据video_Name删除某些视频,调用delVideo()方法将相关信息删除。关键代码如下:
UpLoadForm ulf = (UpLoadForm)form;
String video_Name = ulf.getVideo_Name();
ServletContext servletContext = this.getServlet().getServletContext();
String path = servletContext.getRealPath("");
File filename = new File(path+"/uploadV/"+video_Name);
filename.delete();
UpLoadManager um = new UpLoadManager();
boolean flag = um.delVideo(video_Name);
6.2.7 作业管理模块
本模块在学生用户的主页是学生将自己的作业上传到服务器下的uploadT文件夹中,还可以下载老师批改后上传的作业。在教师用户的主页中老师将学生上传的作业下载下来,之后再将批改好的作业上传到服务器中,供学生下载。上传作业与上传视频类似,只不过多了个String user_name = uploadFile.getUser_name();用来收集上传试卷的用户名。关键代码如下:
UpLoadForm uploadFile = (UpLoadForm)form;
FormFile file = uploadFile.getFile();
String test_Name = file.getFileName();
String test_Time = uploadFile.getTest_Time();
String user_name = uploadFile.getUser_name();
System.out.println("时间="+test_Time);
ServletContext servletContext = this.getServlet().getServletContext();
String path = servletContext.getRealPath("");
FileOutputStream outPut = new FileOutputStream(path+"/uploadT/"+file.getFileName());
outPut.write(file.getFileData());
outPut.flush();
outPut.close();
UpLoadManager ulm = new UpLoadManager();
boolean flag = ulm.testAdd(test_Name, test_Time,user_name);
6.2.8 在线答疑模块
在这个模块中学生和教师可以在线交流,学生可以向老师在线提出问题,老师将在线回答。
学生或者教师将说的话发送,将先存到数据中,随之再将数据库中的后20条记录取出,在message.jsp中显示。在线答疑页面的主要代码如下:
order="1">
6.2.9 友情链接管理模块
教师还可将自己知道的一些好的网站添加到网站里,把友情链接的网名和网址添加进去,学生会在页面上看见添加进的网站名字,用户可以点网站名进入相应的网站。
为了方便管理和安全,将所有的sql语句都封装在一个Sql类中,并且每条语句都定义成public static final类的,这样就不允许有别的语句继承它们。具体的代码如下:
public final class Sql {
//用户登录
public static final String login_tb_user = "select count(*) from tb_user where user_name=? and user_password=?";
//用户注册向数库数中增加数据
public static final String registAdd_tb_user ="insert into tb_user (user_name,user_password,realname,email)" +"values( ?, ?, ?, ? )";
// publi
上一篇:JSP论文:浅议在线CD销售系统的开发及其应用