ServletRequest get name of actual page

10,226

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)

Share:
10,226
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    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

  • Admin
    Admin almost 13 years
    perfect. I didn't think about casting. Casting always hurts my soul. But that ways it works. Quite ugly :-)
  • Bozho
    Bozho almost 13 years
    You will have to get used to casting in servlet filters. Btw, if the answer works for you, you can mark it as accepted (tick below the vote counter)
  • Admin
    Admin almost 13 years
    Still had to wait 4 min to tick it :-)