Servlet class accessibility from external web.xml

I have two web applications. But only one of them includes the Java servlet class. I want to access this servlet class from the web.xml file of another application. Is it possible. If so, how will this be possible ?.

+3
source share
1 answer

You cannot do this at web.xml. However, you can create a new servlet, which in turn redirects / redirects the request to the servlet of another web application. Redirecting is easy, just provide the URL to a specific servlet.

response.sendRedirect("/otherwebapp/theservlet");

. - . servletcontainer, -. , , Tomcat, , servletcontainer: - crossContext <Context> true:

<Context crossContext="true">

ServletContext#getContext() :

ServletContext othercontext = getServletContext().getContext("/otherwebapp");

, :

othercontext.getRequestDispatcher("/theservlet").forward(request, response);
+2

Source: https://habr.com/ru/post/1758668/


All Articles