qq_27630033 2017-12-08 02:08 采纳率: 0%
浏览 2062

web容器是tomcat,连续发送多次请求为什么串行执行,而且多次请求在不同的线程中,求解答!!!

连续发送三次请求


这是控制台输出

servlet源代码如下:
public class ServletDemo1 extends HttpServlet {
private ServletConfig config;

@Override
public void init(ServletConfig config){
    this.config = config;
}


@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    System.out.println(Thread.currentThread().getName());
    System.out.println(new Date());
    System.out.println(request.getRemotePort());
    try {
        Thread.sleep(8000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    String thread = Thread.currentThread().getName();

    ServletContext sc = this.config.getServletContext();
    sc.setAttribute("data","milk");
    String url = sc.getInitParameter("url");

    String initName = this.config.getInitParameter("name");
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<!DOCTYPE HTML PUBLIC \"-//W3C HTML 4.01 Transitional//EN\">");
    out.println("<HTML>");
    out.println(" <HEAD><TITLE>A Servlet Written By Milk</TITLE></HEAD>");
    out.println("<BODY>");
    out.println("This is "+initName+url+"$"+thread+"$");
    out.println(this.getClass());
    out.println(",using the GET method");
    out.println("</BODY>");
    out.println("</HTML>");
    out.flush();
    out.close();
}

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    doGet(request,response);
}
    }
  • 写回答

3条回答 默认 最新

  • fengqingyuebai19 2017-12-08 03:23
    关注

    地址后面加参数,比如
    localhost:8080/sevlet/ServletDemo1?1
    localhost:8080/sevlet/ServletDemo1?2

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况