Javatpoint Logo
Javatpoint Logo

Spring MVC Multiple View page Example

Here, we redirect a view page to another view page.

Let's see the simple example of a Spring Web MVC framework. The steps are as follows:

  • Load the spring jar files or add dependencies in the case of Maven
  • Create the controller class
  • Provide the entry of controller in the web.xml file
  • Define the bean in the separate XML file
  • Create the other view components
  • Start the server and deploy the project

Directory Structure of Spring MVC

Spring MVC Multiple View page

1. Add dependencies to pom.xml

2. Create the request page

Let's create a simple jsp page containing a link.

index.jsp

3. Create the controller class

Let's create a controller class that returns the JSP pages. Here, we pass the specific name with a @Requestmapping annotation to map the class.

HelloController.java

4. Provide the entry of controller in the web.xml file

web.xml

5. Define the bean in the xml file

Now, we also provide view resolver with view component.

Here, the InternalResourceViewResolver class is used for the ViewResolver.

The prefix+string returned by controller+suffix page will be invoked for the view component.

This xml file should be located inside the WEB-INF directory.

spring-servlet.xml

6. Create the other view components

viewpage.jsp

final.jsp

Output:

Spring MVC Multiple View page
Spring MVC Multiple View page
Spring MVC Multiple View page






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA