m0_73624731 2023-02-06 21:19 采纳率: 100%
浏览 14
已结题

javaweb中出现问题

跟着b站博主做到了p15遇到的删除后跳转http://localhost:8080/Shop/manage/admin_douserselect?cp=null

img

img


img


img


img


img

img

img

img

用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 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);
}


  • 写回答

2条回答 默认 最新

  • pzzhao 2023-02-06 22:05
    关注

    后端参数拼错了,页面用的cpage,后端取的时候用的是 cpape

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月17日
  • 已采纳回答 2月9日
  • 创建了问题 2月6日

悬赏问题

  • ¥15 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
  • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET
  • ¥30 写segy数据时出错3
  • ¥100 linux下qt运行QCefView demo报错
  • ¥50 F1C100S下的红外解码IR_RX驱动问题
  • ¥20 基于matlab的航迹融合 航迹关联 航迹插补
  • ¥15 用Matlab实现图中的光线追迹
  • ¥15 联想笔记本开机出现系统更新界面