ajax的servlet

package com.liujinghe2.controller;

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 java.io.IOException;

@WebServlet("/ajaxServlet")
public class AjaxServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
System.out.println("请求方式:"+request.getMethod());
response.setContentType("text/html;charset=utf-8");
//获取请求参数
String username = request.getParameter("username");
//休眠5秒
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(username);
//响应给浏览器
response.getWriter().write("欢迎"+username);
}
}
posted @ 2021-09-23 21:19  张三疯321  阅读(31)  评论(0编辑  收藏  举报