1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| @WebServlet("/findUserServlet") public class findUserServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); String username = request.getParameter("username"); Map<String,Object> map = new HashMap<String, Object>(); if ("hxx".equals(username)){ map.put("userExist",true); map.put("msg","此用户太受欢迎,请更换一个名字"); }else { map.put("userExist",false); map.put("msg","用户名可用"); } ObjectMapper objectMapper = new ObjectMapper(); objectMapper.writeValue(response.getWriter(),map); }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } }
|