批量刪除后不能跳轉(zhuǎn)到list頁面,單個刪除后卻可以
package com.imooc.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.imooc.service.MaintainService;
@SuppressWarnings("serial")
public class DeleteBatchServlet extends HttpServlet ? {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//設(shè)置編碼
req.setCharacterEncoding("UTF-8");
//初始化服務(wù)
MaintainService maintainService=new MaintainService();
//接受頁面的值
String[] ids=req.getParameterValues("id");
maintainService.deleteBatch(ids);
//在上面用jdbc把數(shù)據(jù)庫取出來之后放在messageList里面,然后就可以轉(zhuǎn)發(fā)了,轉(zhuǎn)發(fā)到由req帶到前臺去使用請求轉(zhuǎn)發(fā),就是servlet那里傳過來的請求會直接轉(zhuǎn)給這個頁面來處理
//下面兩行中第二行是錯的,直接跳是不行的,因為沒有查詢數(shù)據(jù)的過程
req.getRequestDispatcher("/List.action").forward(req, resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doGet(req, resp);
}
}
2016-10-23
可不可以看一下你的單個刪除的代碼?
2016-08-22
跳轉(zhuǎn)朱代碼是單個刪除那里復(fù)制過來的,按理來說沒問題啊