-
peng111说:
servlet自定义方法需要配置什么条件才能接受到Ajax的值
A:需要配置如下的几个条件:
(1)Servlet需要设置@WebServlet注解:@WebServlet(name="AjaxServlet",urlPatterns={"/AjaxServlet"})
(2)Servlet需要重写doPost方法:protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
(3)设置请求编码:request.setCharacterEncoding("utf-8");
(4)设置响应类型:response.setContentType("text/html;charset=utf-8");
(5)获取Ajax传递过来的参数:String param=request.getParameter("param");