I just started using Spring. I came across a lot tutorials. I saw more examples using InternalResourceViewResolver
than UrlBasedViewResolver
. I looked at the Spring documentation, but I can't figure out the benefit of using one or the other. Can someone provide some explanation?
Below, we will discuss about three important View Resolver implementations provided by Spring MVC, InternalResourceViewResolver , XmlViewResolver and ResourceBundleViewResolver .
The InternalResourceViewResolver is used to resolve the provided URI to actual URI. The following example shows how to use the InternalResourceViewResolver using the Spring Web MVC Framework. The InternalResourceViewResolver allows mapping webpages with requests.
Go to the src > main > webapp > WEB-INF > right-click > New > Folder and name the folder as views. Then views > right-click > New > JSP File and name your first view.
The InternalResourceViewResolver is an implementation of ViewResolver in Spring MVC framework which resolves logical view name e.g. "hello" to internal physical resources e.g. Servlet and JSP files e.g. jsp files placed under WEB-INF folder.
InternalResourceViewResolver
is a convenient subclass of UrlBasedViewResolver
.
The JavaDoc describes some added properties in InternalResourceViewResolver
that might be useful in some situations:
Convenient subclass of UrlBasedViewResolver that supports InternalResourceView (i.e. Servlets and JSPs) and subclasses such as JstlView.
AlwaysInclude
: Controls whether either a forward or include is done.
ExposeContextBeansAsAttributes
: Allows all beans in context to be available as request attributes, which means they can be referenced from the EL in JSP.
ExposedContextBeanNames
: If non-null, specifies the list of beans that will be exposed, as opposed to all of them.
Source from spring forum : Spring Q&A forum
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With