📄 newstypeservlet.java
字号:
package servlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.servlet.http.HttpSession;
import bean.*;
import java.sql.SQLException;
import DB.newstypeDAO;
public class NewstypeServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
request.setCharacterEncoding("GBK");
String type = request.getParameter("type");
newstypeDAO cot = new newstypeDAO();
newstypeBean bean = new newstypeBean();
try {
if (type.equals("add")) {
String kindname = request.getParameter("kindname");
String name = request.getParameter("typename");
bean.setKindname(kindname);
bean.setName(name);
//增加动作
boolean host = false;
ArrayList list = (ArrayList) cot.getnewstype();
host = cot.insterfirst(bean);
//判断添加是否正确
if (host == true) {
request.setAttribute("list", list);
RequestDispatcher dis = request.getRequestDispatcher(
"main/newstypelist.jsp");
dis.forward(request, response);
}
}
if (type.equals("leibei")) {
//显示新闻的列表
ArrayList list = (ArrayList) cot.getnewstype();
request.setAttribute("list", list);
RequestDispatcher dis = request.getRequestDispatcher(
"main/newstypelist.jsp");
dis.forward(request, response);
}
if (type.equals("del")) {
//删除动作
boolean flat = false;
String newstypeid[] = request.getParameterValues("check");
//循环得到被选中的ID号
for (int i = 0; i < newstypeid.length; i++) {
bean.setID(newstypeid[i]);
if(!cot.delectnewstype(bean))
{
flat=false;
break;
}
}
flat = cot.delectnewstype(bean);
//判断删除是否成功
if (flat == true) {
ArrayList list = (ArrayList) cot.getnewstype();
request.setAttribute("list", list);
RequestDispatcher dis = request.getRequestDispatcher(
"main/newstypelist.jsp");
dis.forward(request, response);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
//Clean up resources
public void destroy() {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -