why JSP pages not showing when using multiple view resolver in Spring boot?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



why JSP pages not showing when using multiple view resolver in Spring boot?



I have added multiple view resolver for PDF, Excel and InternalResourceViewResolver for JSP files. PDF and Excel resolver works fine but when I call /test that is calling my test (test.jsp) I see a blank page. But when I remove other resolvers or disable my webconfig then test.jsp (/test) loads fine.



Following is the error I see when calling /test (binded to test controller and test.jsp):


2018-08-11 23:43:06.191 ERROR 12136 --- [nio-9090-exec-1] o.s.boot.web.support.ErrorPageFilter : Cannot forward to error page for request [/test] as the response has already been committed. As a result, the response may have the wrong status code. If your application is running on WebSphere Application Server you may be able to resolve this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService to false



Also, following is my webconfig responsible for adding multiple resolvers (pdf, excel and jsp pages):


@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer)
configurer
.defaultContentType(MediaType.APPLICATION_JSON)
.favorPathExtension(true);


@Override
public void configureDefaultServletHandling(
DefaultServletHandlerConfigurer configurer)
configurer.enable();


/*
* Configure ContentNegotiatingViewResolver
*/
@Bean
public ViewResolver contentNegotiatingViewResolver(ContentNegotiationManager manager)
ContentNegotiatingViewResolver resolver = new ContentNegotiatingViewResolver();
resolver.setContentNegotiationManager(manager);

// Define all possible view resolvers
List<ViewResolver> resolvers = new ArrayList<>();

resolvers.add(internalResourceViewResolver());
resolvers.add(pdfViewResolver());
resolvers.add(excelViewResolver());

resolver.setViewResolvers(resolvers);
return resolver;


@Bean
public ViewResolver internalResourceViewResolver()
InternalResourceViewResolver resolver = new InternalResourceViewResolver();

resolver.setPrefix("/WEB-INF/jsp");
resolver.setSuffix(".jsp");
return resolver;


/*
* Configure View resolver to provide XLS output using Apache POI library to
* generate XLS output for an object content
*/
@Bean
public ViewResolver excelViewResolver()
return new ExcelViewResolver();


/*
* Configure View resolver to provide Pdf output using iText library to
* generate pdf output for an object content
*/
@Bean
public ViewResolver pdfViewResolver()
return new PdfViewResolver();






Do you added controller class?
– Sumesh TG
Aug 13 at 10:57






yes. Actually i found the problem. it was strangely only a missing slash. fixed by just adding that at end of the path that jsp files resides: resolver.setPrefix("/WEB-INF/jsp/");
– Jason Foster
Aug 15 at 12:03









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard