Communication between two web application in same server

后端 未结 5 1788
攒了一身酷
攒了一身酷 2020-12-09 10:41

All,

I have 2 web applications, Web1 and Web2, deployed on my tomcat server. I want classes in Web1 to call methods on classes in Web2. One way to do this is using

5条回答
  •  不思量自难忘°
    2020-12-09 11:29

    Yes you can do it using javax.servlet.ServletContext and javax.servlet.RequestDispatcher API's. Here it is how it can be done from Web1:

    ServletContext otherContext = servletContext.getContex("/Web2");
    RequestDispatcher dispathcer = otherContext.getRequestDispatcher("/a/b.jsp");
    
    dispatcher.forward(request, response);
    //or
    dispatcher.include(request, response);
    

提交回复
热议问题