Is it possible to specify complete path of a view file in controller without making use of view resolver?
Suppose I have just one file, say a XML file in my views and for a particular request I want to serve that XML file. By using view resolver, I am not able to find a way to pick up such a file and server it directly like me serve a jsp. So, for such a case can I do something in which I specify complete path in controller like we used to do in servlet's getRequestDispatcher?
My view resolver is currently configured for JSP only, I am not able to find a view using view resolvers to handle this situation, my view resolver is like as given below:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
Currently I am using getRequestDispatcher in controller for this? Is there any spring based alternative?
Spring MVC allows you to create a request handling method with different return types, see the reference guide. Instead of a String return a View from your method which points directly to your resource. When you return a View instance Spring MVC will not consult a ViewResolver but simply use the view as is. For you case you probably want to use an InternalResourceView.
@RequestMapping
public View yourRequestHandlingMethod() {
return new InternalResourceView("path/to/resource");
}
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