is it possible a java web application can call another java web application in same localhost of tomcat server

我的梦境 提交于 2021-01-28 05:00:36

问题


i am trying to deploy two web applications say appA and appB in same local host tomcat server and when the both the applications are up in running is it possible to call appB to appA using ajax call or redirect


回答1:


What you are looking for toa chieve can be done using the following tomcat parameter:

(from docs)

crossContext

Set to true if you want calls within this application to ServletContext.getContext() to successfully return a request dispatcher for other web applications running on this virtual host. Set to false (the default) in security conscious environments, to make getContext() always return null.

example:

http://blog.imaginea.com/cross-context-communication-between-web-applications/

related discussions: What does the crossContext attribute do in Tomcat? Does it enable session sharing?




回答2:


Try This Way

ServletContext ctx = request.getServletContext().getContext("/otherapp");
request.setAttribute("MESSAGE", "Hello There!");
RequestDispatcher dispatcher = ctx.getRequestDispatcher("/hello.jsp");
dispatcher.forward(request, response);

Note

To enable this feature in Tomcat we need to enable the crossContext attribute by setting the value to true, the default value is false.



来源:https://stackoverflow.com/questions/29160454/is-it-possible-a-java-web-application-can-call-another-java-web-application-in-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!