管理员查询管理员查询用户名密码类型操作session.getAttribute("user");%>${user.username}${u..._html和ajax删除用户">
当前位置:   article > 正文

ajax删除一个用户信息,ajax删除用户问题

html和ajax删除用户

String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";

%>

管理员查询

管理员查询


用户名密码类型操作

session.getAttribute("user");

%>

${user.username}${user.password}

超级管理员

普通管理员

删除

function shanchu(e) {

var value=e.getAttribute("data-value");

$.ajax({

url:"deleteServlet",

type:"post",

data:{"username":value},

dataType:"json",

success:function (userList) {

var userList = eval(userList);

console.log(userList);

var content=null;

if(userList!=null){

for(var i in userList){

var username=userList[i].username;

var password=userList[i].password;

var level=userList[i].level;

content = content + "

" + username + "" + password + "" + level + "";

}

$("#cont>tr").remove();

$("#cont").html(content);

}

}

});

}

package com.vincent.course.servlet;

import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.JSONArray;

import com.vincent.course.data.CourseDaoImpl;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

import java.util.Collections;

import java.util.List;

import java.util.Map;

public class DeleteServlet extends HttpServlet {

@Override

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

doPost(req,resp);

}

@Override

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

req.setCharacterEncoding("utf-8");

resp.setCharacterEncoding("utf-8");

CourseDaoImpl cdi = new CourseDaoImpl();

String username = req.getParameter("username");

List> userList = cdi.getAllUsers();

//删除用户

cdi.delUser(username);

req.getSession().setAttribute("userList",userList);

//        req.getRequestDispatcher("/jsp/selectUsers.jsp").forward(req,resp);

//将结果回传

//将userList进行JSON序列化

JSONArray jsonArray = new JSONArray(Collections.singletonList(userList));

resp.getOutputStream().write(jsonArray.toString().getBytes("UTF-8"));

}

}

问题1:使用ajax删除用户后,界面不直接显示,要重新点击查询管理员才能看到结果

问题2:为什么我添加普通管理员进去之后,退出在登录,却显示用户不存在?

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/100850
推荐阅读
相关标签
  

闽ICP备14008679号