Display elements in jsp lists if servlet exists

30 views Asked by At

I have a 2 war (a.war , b.war) both were deployed in the tomcat. There are some jsp files in a.war which displays list of items in the list.

I need to display 5 items in tab on jsp page only if the b.war is also deployed , otherwise i will display only 3 items if b.war is not deployed.

Say there is servlet named /b/jobmgmt in b.war.

Can someone tell us,how can validate that b.war is deployed or not from the JSP page belongs to a.war using the servlet.

Thanks in advance.

Regards,

Raghavan

1

There are 1 answers

1
Jozef Chocholacek On

Basically, there are two possible approaches:

1) Define a <context-param> in web.xml of a.war, let's say checkURL, and put there the URL of the /b/jobmgmt as value, e.g. http://localhost:8080/b.jobmgmt. Then use getServletContext().getInitParameter("checkURL"); to get it in your JSP, and an HTTP call to verify, if the servlet is there and alive.

2) You can use cross-context communication as described e.g. here: https://blog.imaginea.com/cross-context-communication-between-web-applications/

Both approaches have their pros and cons, you have to choose according to your situation.