Is there anyway to use plain jsp files without a controller mixed with thymeleaf views using controllers in Spring Boot/MVC?
For example, a standard controller is as follows;
@RequestMapping("/")
public String get() {
return "view";
}
Which works exactly as expected, but is it possible to map ".jsp" files put in a folder to any url for example test.jsp would go to www.website.com/test.jsp
Regards.
I use the following configuration in
servlet-context.xml
(the contextConfigLocation of the DispatcherServlet):In order to render the response with a JSP, in the controller I return a string like the following:
whereas to render with a thymeleaf template, I do the following:
Of course, the physical location of the
.jsp
and.html
files must match the view name returned by the controllers. So, according to how the resolvers are configured, you will have to place.jsp
files inside/views/jsp
and.html
files (for thymeleaf) inside/views/templates
If you want a url like
www.website.com/test.jsp
to be rendered with thetest.jsp
view, you can simply put the aformentiond jsp file inside the root directory of your webapp. The request should be resolved by the JSP servlet, if no strange configuration is in place. In fact, a servlet container like Tomcat normally have this specification in its globalweb.xml
file:and
If you want something more customized and specific, you will have to modify your configuration accordingly. For example, remove the JSP servlet from you servlet container's web.xml and map *.jsp url in the appropriate controllers