📄 addnewcategory.java
字号:
package control;
import java.io.IOException;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;
/**
* 用来添加新的板块Category
* @author steven
*
*/
public class AddNewCategory extends HttpServlet
{
public void init(ServletConfig config)throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
if(((Boolean)req.getSession().getAttribute("AdminOrNot")).booleanValue())//如果是管理员
{
req.setCharacterEncoding("gbk");
Vector vc = new Vector();
String CName = new String(req.getParameter("CName")).trim();
CName = CName.replaceAll("\\,*", "").replaceAll("\\s", "").replaceAll("\\,", "");
System.out.println(CName);
String Parent = req.getParameter("selectcategory");
String Detail = (String)req.getParameter("detail");
CategoryCom com2 = new CategoryCom("jdbc:mysql://localhost/mybbs","root", "root123");
if(com2.isExitCategory(CName)) //如果该分类存在
{
tiaoZhuan(req,res,"/AddCategoryFail.jsp");
}
else
{
GregorianCalendar timenow=new GregorianCalendar();
int year=timenow.get(Calendar.YEAR);
int month=timenow.get(Calendar.MONTH)+1;
int day=timenow.get(Calendar.DAY_OF_MONTH);
String date =year+"-"+month+"-"+day;
if(Parent.equals("null"))
{
Parent = CName;
RelationCom com = new RelationCom("jdbc:mysql://localhost/mybbs","root", "root123");
com.addRelation("null", CName,CName);
}
else
{
String PCName = null;
if(Parent.contains(","))
{
PCName = Parent.substring(Parent.lastIndexOf(",")+1);
}
else
PCName = Parent;
Parent = Parent+","+CName;
RelationCom com = new RelationCom("jdbc:mysql://localhost/mybbs","root", "root123");
com.addRelation(PCName, CName,Parent);
}
com2.addCategory(CName, date, 0, Detail,Parent);
vc = com2.getAllCatefory(); //用来存储Category
req.setAttribute("demo", vc);
req.setAttribute("command", "show");
tiaoZhuan(req,res,"/DengLuOK.jsp");
}
}
}
public void tiaoZhuan(HttpServletRequest req,HttpServletResponse res,String page)throws ServletException,IOException
{
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(page);
dispatcher.forward(req, res);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -