管理员查询管理员查询用户名密码类型操作session.getAttribute("user");%>${user.username}${u..._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:为什么我添加普通管理员进去之后,退出在登录,却显示用户不存在?
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。