Spring MVC Serve HTML JSP Page

Spring MVC Serve HTML JSP Page

In this demo you will see how to return either static HTML or JSP page from Spring MVC application. Please follow steps below:

Summary: To return either html or jsp page from spring mvc don’t include¬†InternalResourceViewResolver bean to return particular extension with page as shown in example below where it says: include suffix with all the resources when we return page from spring controller:

Note: As you will see in below example we have removed InternalResourceViewResolver bean form dispatcher-servlet.xml file and adding page with extension from spring mvc controller.

Steps:

  • Create maven project name: SpringMVCHTMLReturn
  • Final project structure:

Spring MVC Serve HTML JSP Page

  • dispatcher-servlet.xml:

  • SpringMVCController:

  • index.html:

  • Web page output:

Spring MVC Serve HTML JSP Page

  • To return JSP page from controller change controller code as below:

  • Web page output:

Spring MVC Serve HTML JSP Page

For more information please read Spring MVC tutorial here.

download Download Project:  SpringMVCHTMLReturn

Leave a Reply

Your email address will not be published. Required fields are marked *