Class DefaultRequestToViewNameTranslator
- java.lang.Object
 - org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator
 
- All Implemented Interfaces:
 RequestToViewNameTranslator
public class DefaultRequestToViewNameTranslator extends Object implements RequestToViewNameTranslator
RequestToViewNameTranslatorthat simply transforms the URI of the incoming request into a view name.Can be explicitly defined as the
viewNameTranslatorbean in aDispatcherServletcontext. 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
prefixand asuffixadded as appropriate.The stripping of the leading slash and file extension can be disabled using the
stripLeadingSlashandstripExtensionproperties, respectively.Find below some examples of request to view name translation.
http://localhost:8080/gamecast/display.html»displayhttp://localhost:8080/gamecast/displayShoppingCart.html»displayShoppingCarthttp://localhost:8080/gamecast/admin/index.html»admin/index
- Since:
 - 2.0
 - Author:
 - Rob Harrop, Juergen Hoeller
 - See Also:
 RequestToViewNameTranslator,ViewResolver
Constructor Summary
Constructors Constructor Description DefaultRequestToViewNameTranslator()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetViewName(HttpServletRequest request)Translates the request URI of the incomingHttpServletRequestinto the view name based on the configured parameters.voidsetAlwaysUseFullPath(boolean alwaysUseFullPath)Set if URL lookup should always use the full path within the current servlet context.voidsetPrefix(String prefix)Set the prefix to prepend to generated view names.voidsetRemoveSemicolonContent(boolean removeSemicolonContent)Set if ";" (semicolon) content should be stripped from the request URI.voidsetSeparator(String separator)Set the value that will replace '/' as the separator in the view name.voidsetStripExtension(boolean stripExtension)Set whether or not file extensions should be stripped from the URI when generating the view name.voidsetStripLeadingSlash(boolean stripLeadingSlash)Set whether or not leading slashes should be stripped from the URI when generating the view name.voidsetStripTrailingSlash(boolean stripTrailingSlash)Set whether or not trailing slashes should be stripped from the URI when generating the view name.voidsetSuffix(String suffix)Set the suffix to append to generated view names.voidsetUrlDecode(boolean urlDecode)Set if the context path and request URI should be URL-decoded.voidsetUrlPathHelper(UrlPathHelper urlPathHelper)Set theUrlPathHelperto use for the resolution of lookup paths.protected StringtransformPath(String lookupPath)Transform the request URI (in the context of the webapp) stripping slashes and extensions, and replacing the separator as required.
Constructor Detail
DefaultRequestToViewNameTranslator
public DefaultRequestToViewNameTranslator()
Method Detail
setPrefix
public void setPrefix(String prefix)
Set the prefix to prepend to generated view names.- Parameters:
 prefix- the prefix to prepend to generated view names
setSuffix
public void setSuffix(String suffix)
Set the suffix to append to generated view names.- Parameters:
 suffix- the suffix to append to generated view names
setSeparator
public void setSeparator(String separator)
Set the value that will replace '/' as the separator in the view name. The default behavior simply leaves '/' as the separator.
setStripLeadingSlash
public void setStripLeadingSlash(boolean stripLeadingSlash)
Set whether or not leading slashes should be stripped from the URI when generating the view name. Default is "true".
setStripTrailingSlash
public void setStripTrailingSlash(boolean stripTrailingSlash)
Set whether or not trailing slashes should be stripped from the URI when generating the view name. Default is "true".
setStripExtension
public void setStripExtension(boolean stripExtension)
Set whether or not file extensions should be stripped from the URI when generating the view name. Default is "true".
setAlwaysUseFullPath
public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Set if URL lookup should always use the full path within the current servlet context. Else, the path within the current servlet mapping is used if applicable (i.e. in the case of a ".../*" servlet mapping in web.xml). Default is "false".
setUrlDecode
public void setUrlDecode(boolean urlDecode)
Set if the context path and request URI should be URL-decoded. Both are returned undecoded by the Servlet API, in contrast to the servlet path.Uses either the request encoding or the default encoding according to the Servlet spec (ISO-8859-1).
- See Also:
 UrlPathHelper.setUrlDecode(boolean)
setRemoveSemicolonContent
public void setRemoveSemicolonContent(boolean removeSemicolonContent)
Set if ";" (semicolon) content should be stripped from the request URI.
setUrlPathHelper
public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Set theUrlPathHelperto 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.
getViewName
public String getViewName(HttpServletRequest request)
Translates the request URI of the incomingHttpServletRequestinto the view name based on the configured parameters.- Specified by:
 getViewNamein interfaceRequestToViewNameTranslator- Parameters:
 request- the incomingHttpServletRequestproviding the context from which a view name is to be resolved- Returns:
 - the view name (or 
nullif no default found) - See Also:
 UrlPathHelper.getLookupPathForRequest(javax.servlet.http.HttpServletRequest),transformPath(java.lang.String)
transformPath
protected String transformPath(String lookupPath)
Transform the request URI (in the context of the webapp) stripping slashes and extensions, and replacing the separator as required.- Parameters:
 lookupPath- the lookup path for the current request, as determined by the UrlPathHelper- Returns:
 - the transformed path, with slashes and extensions stripped if desired