问题
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 totrue
, the default value isfalse
.
来源:https://stackoverflow.com/questions/29160454/is-it-possible-a-java-web-application-can-call-another-java-web-application-in-s