spring-framework / org.springframework.web.servlet.view / DefaultRequestToViewNameTranslator

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.

Author
Rob Harrop

Author
Juergen Hoeller

Since
2.0

See Also
org.springframework.web.servlet.RequestToViewNameTranslatororg.springframework.web.servlet.ViewResolver

Constructors

<init>

DefaultRequestToViewNameTranslator()

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

Functions

getViewName

open fun getViewName(request: HttpServletRequest): String

Translates the request URI of the incoming HttpServletRequest into the view name based on the configured parameters.

setAlwaysUseFullPath

open fun setAlwaysUseFullPath(alwaysUseFullPath: Boolean): Unit

Shortcut to same property on underlying UrlPathHelper.

setPrefix

open fun setPrefix(prefix: String): Unit

Set the prefix to prepend to generated view names.

setRemoveSemicolonContent

open fun setRemoveSemicolonContent(removeSemicolonContent: Boolean): Unit

Set if ";" (semicolon) content should be stripped from the request URI.

setSeparator

open fun setSeparator(separator: String): Unit

Set the value that will replace '/' as the separator in the view name. The default behavior simply leaves '/' as the separator.

setStripExtension

open fun setStripExtension(stripExtension: Boolean): Unit

Set whether or not file extensions should be stripped from the URI when generating the view name. Default is "true".

setStripLeadingSlash

open fun setStripLeadingSlash(stripLeadingSlash: Boolean): Unit

Set whether or not leading slashes should be stripped from the URI when generating the view name. Default is "true".

setStripTrailingSlash

open fun setStripTrailingSlash(stripTrailingSlash: Boolean): Unit

Set whether or not trailing slashes should be stripped from the URI when generating the view name. Default is "true".

setSuffix

open fun setSuffix(suffix: String): Unit

Set the suffix to append to generated view names.

setUrlDecode

open fun setUrlDecode(urlDecode: Boolean): Unit

Shortcut to same property on underlying UrlPathHelper.

setUrlPathHelper

open fun setUrlPathHelper(urlPathHelper: UrlPathHelper): Unit

Set the org.springframework.web.util.UrlPathHelper to use for the resolution of lookup paths.

Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple web components.