intpartid=partdata.elementAt(i).getId();
try{
Commentc=CommentDao.getLastComment(partid);
Stringdate=c.getDate();
Stringtime=CommonUtil.getCommentDate(date);
c.setDate(time);
Stringtitle=c.getName();
if(title!
=null){
if(title.length()>12){
Stringx=title.substring(0,12);
x=x+"...";
c.setName(x);
}
vcomment.addElement(c);
}
}catch(Exceptione){
e.toString();
}
}
request.setAttribute("lastcomments",vcomment);//最后的回贴
request.setAttribute("PartData",partdata);
request.getRequestDispatcher("main.jsp").forward(request,response);
BBS发贴界面
关于代码
request.setCharacterEncoding("gb2312");//修改request编码方式
Stringtype=request.getParameter("gototype");//通过标记判断跳转而来的页面
intid=Integer.parseInt(request.getParameter("partid"));//获取版块id
Stringtitle=request.getParameter("title");
Stringtext=request.getParameter("FCKBack");
if(type.equals("0")){//如果为0则表示从comment.jsp跳转而来,要判断是否合法
Useru=(User)request.getSession().getAttribute("user");
if(u==null){//未登录则跳转至登陆页面
response.sendRedirect("Login.jsp");
}else{//登录用户跳转至发帖页面
request.setAttribute("partid",id);
request.getRequestDispatcher("AddComment.jsp").forward(request,response);
}
}else{//表示从AddComment.jsp跳转而来
Dated=newDate();
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:
mm:
ss");
Stringtime=sdf.format(d);//格式化日期
Useru=(User)request.getSession().getAttribute("user");
intuid=u.getId();//用户id
DBConnectdb=newDBConnect();
try{
Stringsql="insertintobbs_commentvalues('"+title+"','"+text+"',"+uid+",'"+time+"','"+id+"',0,1)";//编写sql语句
inti=db.executeUpdate(sql);
if(i>0){//如果大于0则表示插入数据库成功
request.getRequestDispatcher("CommentServlet?
partid="+id).forward(request,response);
}
}catch(Exceptione){
e.printStackTrace();}
request.setCharacterEncoding("gb2312");//修改request编码方式
Stringtype=request.getParameter("gototype");//通过标记判断跳转而来的页面
intid=Integer.parseInt(request.getParameter("partid"));//获取版块id
Stringtitle=request.getParameter("title");
Stringtext=request.getParameter("FCKBack");
if(type.equals("0")){//如果为0则表示从comment.jsp跳转而来,要判断是否合法
Useru=(User)request.getSession().getAttribute("user");
if(u==null){//未登录则跳转至登陆页面
response.sendRedirect("Login.jsp");
}else{//登录用户跳转至发帖页面
request.setAttribute("partid",id);
request.getRequestDispatcher("AddComment.jsp").forward(request,response);
}
}else{//表示从AddComment.jsp跳转而来
Dated=newDate();
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:
mm:
ss");
Stringtime=sdf.format(d);//格式化日期
Useru=(User)request.getSession().getAttribute("user");
intuid=u.getId();//用户id
DBConnectdb=newDBConnect();
try{
Stringsql="insertintobbs_commentvalues('"+title+"','"+text+"',"+uid+",'"+time+"','"+id+"',0,1)";//编写sql语句
inti=db.executeUpdate(sql);
if(i>0){//如果大于0则表示插入数据库成功
request.getRequestDispatcher("CommentServlet?
partid="+id).forward(request,response);
}
}catch(Exceptione){
e.printStackTrace();
}
BBS用户注册界面
四、BBS后台的详细设计
BBS后台管理系统
request.setCharacterEncoding("gb2312");//修改request编码方式
Stringtype=request.getParameter("gototype");//通过标记判断跳转而来的页面
intid=Integer.parseInt(request.getParameter("partid"));//获取版块id
Stringtitle=request.getParameter("title");
Stringtext=request.getParameter("FCKBack");
if(type.equals("0")){//如果为0则表示从comment.jsp跳转而来,要判断是否合法
Useru=(User)request.getSession().getAttribute("user");
if(u==null){//未登录则跳转至登陆页面
response.sendRedirect("Login.jsp");
}else{//登录用户跳转至发帖页面
request.setAttribute("partid",id);
request.getRequestDispatcher("AddComment.jsp").forward(request,response);
}
}else{//表示从AddComment.jsp跳转而来
Dated=newDate();
SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:
mm:
ss");
Stringtime=sdf.format(d);//格式化日期
Useru=(User)request.getSession().getAttribute("user");
intuid=u.getId();//用户id
DBConnectdb=newDBConnect();
try{
Stringsql="insertintobbs_commentvalues('"+title+"','"+text+"',"+uid+",'"+time+"','"+id+"',0,1)";//编写sql语句
inti=db.executeUpdate(sql);
if(i>0){//如果大于0则表示插入数据库成功
request.getRequestDispatcher("CommentServlet?
partid="+id).forward(request,response);
}
}catch(Exceptione){
e.printStackTrace();
}
BBS后台添加板块
关于代码
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
Stringtype=request.getParameter("type");
StringmpName=request.getParameter("mpName");
System.out.println("mpName:
"+mpName);
if(type!
=null){
if(type.equals("0")){
DBConnectdb=newDBConnect();
Stringtime=CommonUtil.getTime(newDate());
inti=0;
try{
i=db.executeUpdate("insertintobbs_partvalues('"+mpName+"','"+time+"',1,0,null)");
}catch(Exceptione){
e.printStackTrace();
}
if(i>0){
request.setAttribute("message","主版块添加成功-("+mpName+")");
}
}elseif(type.equals("1")){//添加子版块
StringminiPartName=request.getParameter("minipName");
Stringmpartid=request.getParameter("mpSelect");
DBConnectdb=newDBConnect();
Stringtime=CommonUtil.getTime(newDate());
inti=0;
try{
i=db.executeUpdate("insertintobbs_partvalues('"+miniPartName+"','"+time+"',1,"+mpartid+",null)");
}catch(Exceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
if(i>0){
request.setAttribute("message","子版块添加成功-("+miniPartName+")");
}
}
}
Vectorpartdata=PDao.sqlPartAll();
request.setAttribute("mainparts",partdata);
request.getRequestDispatcher("AddPart.jsp").forward(request,response);
BBS后台修改板块
关于代码
request.setCharacterEncoding("gb2312");
//主版块加入request范围
Stringtype=request.getParameter("type");
Stringpartid=request.getParameter("partid");
System.out.println("partid"+partid);
if(type!
=null){
DBConnectdb=newDBConnect();
if(type.equals("0")){
Stringnewmpname=request.getParameter("newMPName");//获取主版块新名称
Stringmpid=request.getParameter("mpmodifyselect");
try{
db.executeUpdate("updatebbs_partsetname='"+newmpname+"'whereid="+mpid);
}catch(Exceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}elseif(type.equals("1")){
Stringnewsonname=request.getParameter("newSonName");//获取子版块新名称
Stringsonid=request.getParameter("sonpartselect");
try{
db.executeUpdate("updatebbs_partsetname='"+newsonname+"'whereid="+sonid);
}catch(Exceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
if(partid!
=null){
Vectorsonparts=PDao.sqlPart(Integer.parseInt(partid));
request.setAttribute("partid",partid);//将主版块id放置进request内
request.setAttribute("sonparts",sonparts);
}
Vectorpartdata=PDao.sqlPartAll();
request.setAttribute("mainparts",partdata);
request.getRequestDispatcher("ModifyPart.jsp").forward(request,response);
BBS后台删除板块
关于代码
//主版块加入request范围
Stringtype=request.getParameter("type");
Stringpartida=request.getParameter("partida");
if(type!
=null){
DBConnectdb=newDBConnect();
if(type.equals("0")){
Stringmpid=request.getParameter("mpdeleteselect");
try{
db.executeUpdate("updatebbs_partsetstatus=0whereid="+mpid);
}catch(Exceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}elseif(type.equals("1")){
Stringsonid=request.getParameter("sonpartselect");
try{
db.executeUpdate("updatebbs_partsetstatus=0whereid="+sonid);
}catch(Exceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
if(partida!
=null){
Vectorsonparts=PDao.sqlPart(Integer.parseInt(partida));
request.setAttribute("partid",partida);//将主版块id放置进request内
request.setAttribute("sonparts",sonparts);
}
Vectorpartdata=PDao.sqlPartAll();
request.setAttribute("mainparts",partdata);
request.getRequestDispatcher("DeletPart.j