spring-framework / org.springframework.web.servlet / RequestToViewNameTranslator

RequestToViewNameTranslator

interface RequestToViewNameTranslator

Strategy interface for translating an incoming javax.servlet.http.HttpServletRequest into a logical view name when no view name is explicitly supplied.

Author
Rob Harrop

Author
Juergen Hoeller

Since
2.0

Functions

getViewName

abstract fun getViewName(request: HttpServletRequest): String

Translate the given HttpServletRequest into a view name.

Inheritors

DefaultRequestToViewNameTranslator

open class DefaultRequestToViewNameTranslator : RequestToViewNameTranslator

RequestToViewNameTranslator that simply transforms the URI of the incoming request into a view name.

Can be explicitly defined as the viewNameTranslator bean in a org.springframework.web.servlet.DispatcherServlet context. Otherwise, a plain default instance will be used.

The default transformation simply strips leading and trailing slashes as well as the file extension of the URI, and returns the result as the view name with the configured prefix and a suffix added as appropriate.

The stripping of the leading slash and file extension can be disabled using the stripLeadingSlash and stripExtension properties, respectively.

Find below some examples of request to view name translation.

  • http://localhost:8080/gamecast/display.html » display
  • http://localhost:8080/gamecast/displayShoppingCart.html » displayShoppingCart
  • http://localhost:8080/gamecast/admin/index.html » admin/index