Hans Sausage Hans Sausage - 6 months ago 13
Java Question

ServletRequest get name of actual page

I am using a

Filter
and the
doFilter
-Function. I would like to know which site is being requested. Some function giving me something like
/firstDirectoryInWebDirectory/lala.jsp
would be perfect.

What is the way to go here? Using the context will be the right way, but I can't find any good method :-(

Thanks

Answer

request.getRequestURI() should return the part of the URL after the domain.

From there, you can strip the request.getContextPath()

(You'd have to cast the ServletRequest to HttpServletRequest first)