跟着b站博主做到了p15遇到的删除后跳转http://localhost:8080/Shop/manage/admin_douserselect?cp=null
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
<c:if test="${u.USER_STATUS ==1 }">
<a class="link-del" href="javascript:Delete('你确定要删除用户【${u.USER_NAME}】吗' , '/Shop/manage/admin_douserdel?id=${u.USER_ID}&cpage=${cpage}')">删除</a>
</c:if>
</td>
</tr>
</c:forEach>
<script>
function Delete(mess,url){
if (confirm(mess)){
location.href=url;
}
}
package com.Shop.servlet.user;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.Shop.entity.SHOP_USER;
import com.Shop.service.SHOP_USERDao;
/**
* Servlet implementation class DoUserDel
*/
@WebServlet("/manage/admin_douserdel")
public class DoUserDel extends HttpServlet {
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//设置字符集
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String id=request.getParameter("id");
//加入到数据库的用户表中
int count= SHOP_USERDao.del(id);
//成功或失败重定向到哪里
if(count >0 ){
response.sendRedirect("admin_douserselect?cp="+request.getParameter("cpape"));
}else{
PrintWriter out = response.getWriter();
out.write("<script>");
out.write("alert('用户删除失败')");
out.write("location.href='manage/admin_douserselect?cp="+request.getParameter("cpape")+"'");
out.write("<script>");
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
```java
/**
* 删除一个用户
* @param id
* @return
*/
public static int del(String id){
String sql="delete from SHOP_USER where USER_ID=? and USER_STATUS!=2";
Object[] params = {id};
return Basedao.exectuIUD(sql, params);
}