1

Is it intended that Spring MVC doesn't throw ServletException when the expected JSP doesn't exist?
Code snippet below is the part of InternalResourceView, where an exception should be made in my opinion. RequestDispatcher might be null because there's no file on dispatcherPath.
In detail, dispatcherPath looks like /WEB-INF/jsp/v2/post/somename.jsp.

  // Obtain a RequestDispatcher for the target resource (typically a JSP).
  RequestDispatcher rd = getRequestDispatcher(requestToExpose, dispatcherPath);
  if (rd == null) {
 throw new ServletException(
      "Could not get RequestDispatcher for [" + getUrl() +
      "]: Check that the corresponding file exists within your web application archive!");
  }
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
NaHeon
  • 247
  • 1
  • 12
  • 1
    Yes it is, and it is historical. `InternalResourceView` is a `UrlBasedViewResolver` and basically all it does is construct a URL to somewhere. Which might or might not exist. If you want you could provide your own subclass of `JstlView` and implement the `checkResource` method to check if it actually exists. Then configure the `InternalResourceViewResolver` with this view. – M. Deinum Sep 28 '16 at 09:12
  • @M.Deinum Thanks for explanation. But I don't think `JstlView.checkResource` is an appropriate point to check whether jsp exists. 1. checkResource only has Locale parameter 2. ViewResolver might be able to check the existence beforehand. `UrlBasedViewResolver.buildView`, for example. – NaHeon Sep 30 '16 at 05:17
  • It is delegated to the `checkResource` as that knows about the view technology. The view resolver (at least this one) doesn't know about the technology. Next to that the `View` extends `WebApplicationObjectSupport` which has a `ServletContext` so you can perfectly well check it in your `View`. – M. Deinum Sep 30 '16 at 05:41
  • @M.Deinum fully understand what you meant. Thanks alot! – NaHeon Oct 07 '16 at 02:18

0 Answers0