Lucas Batistussi
Lucas Batistussi

Reputation: 2343

How to check whether servlet name exists?

I need to know whether servlet exists or not before forward a request! How I could do this (best way)?

Upvotes: 1

Views: 203

Answers (1)

BalusC
BalusC

Reputation: 1108902

If you're on Servlet 3.0, just check if ServletContext#getServletRegistration() don't return null for the given servlet name.

If you're not on Servlet 3.0 yet, parse the web.xml yourself.

That said, this is a rather strange requirement. Is the servlet added dynamically/programmatically based on some condition or so? It'd probably be more easier to check exactly that condition before forwarding.

Upvotes: 2

Related Questions