Calling Servlet Post from another Servlet

后端 未结 3 928
孤城傲影
孤城傲影 2021-01-12 19:17

I need to call a servlets POST method from another servlet and pass a blob in the servlets parameters. Is this posible, if so how can it be done. PS: I cant use Apache HttpC

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 20:00

    You can get a dispatcher to another servlet in your application and forward it or include it as @Ryan suggests. The code should be something like this inside your first servlet:

    ServletContext context = this.getServletContext();
    RequestDispatcher dispatcher = context.getRequestDispatcher("/otherurltoservlet");
    
    // change your request and response accordingly
    
    dispatcher.forward(request, response);
    

提交回复
热议问题