0% found this document useful (0 votes)
5 views4 pages

Exploring Web MVC Without Spring Boot

Spring MVC is a web framework under the Spring Framework that follows the Model-View-Controller design pattern for building Java-based web applications. Key components include the Model (data storage), View (JSP for display), and Controller (handles HTTP requests), with DispatcherServlet acting as the front controller. The document outlines steps for creating a Spring MVC project, configuring the DispatcherServlet, and using an Internal Resource View Resolver to map logical view names to physical JSP paths.

Uploaded by

lovinidone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Exploring Web MVC Without Spring Boot

Spring MVC is a web framework under the Spring Framework that follows the Model-View-Controller design pattern for building Java-based web applications. Key components include the Model (data storage), View (JSP for display), and Controller (handles HTTP requests), with DispatcherServlet acting as the front controller. The document outlines steps for creating a Spring MVC project, configuring the DispatcherServlet, and using an Internal Resource View Resolver to map logical view names to physical JSP paths.

Uploaded by

lovinidone
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Spring MVC Notes

1 Spring MVC Introduction


1.1 What is Spring MVC?
• A web framework under the Spring Framework.

• Follows the Model-View-Controller (MVC) design pattern.

• Used for building Java-based web applications.

• Powered by Servlets and JavaServer Pages (JSP).

1.2 Key Components


• Model: Java object (POJO) used to store data.

• View: JSP file used to display results to the user.

• Controller: Java class that handles HTTP requests.

1.3 DispatcherServlet
• Acts as the front controller.

• Routes all HTTP requests to appropriate controllers.

2 Creating a Spring MVC Project


2.1 Steps to Create
• Create a Dynamic Web Project in Eclipse.

• Add Maven Nature and create pom.xml.

• Add Spring MVC dependency:


1 < dependency >
2 < groupId > org . springframework </ groupId >
3 < artifactId > spring - webmvc </ artifactId >
4 < version > 5.3.22 </ version >
5 </ dependency >

• Create folder structure:

1
– /src/main/java: Java files (Controller, Model).
– /src/main/webapp/WEB-INF: web.xml, telusko-servlet.xml.
– /views: JSP files.

• Add JSTL and Servlet dependencies if needed.

3 Running Tomcat in Eclipse


3.1 Steps
• Download and configure Apache Tomcat in Eclipse.

• Go to Servers tab → Right click → New → Server.

• Choose Tomcat version (e.g., 9.0).

• Deploy project by dragging into server.

• Start server (green play button) and access via:


1 http :// localhost :8080/ YourAppName

4 DispatcherServlet
4.1 Role
• Handles all incoming HTTP requests.

• Mapped in web.xml.

• Loads its configuration file (e.g., telusko-servlet.xml).

4.2 web.xml Configuration

1 < servlet >


2 < servlet - name > telusko </ servlet - name >
3 < servlet - class > org . springframework . web . servlet .
DispatcherServlet </ servlet - class >
4 </ servlet >
5 < servlet - mapping >
6 < servlet - name > telusko </ servlet - name >
7 <url - pattern >/ </ url - pattern >
8 </ servlet - mapping >

Note: telusko-servlet.xml is searched inside /WEB-INF/.

2
5 Configuring the DispatcherServlet
5.1 telusko-servlet.xml

1 < ctx : component - scan base - package = " com . telusko " / >
2 < mvc : annotation - driven / >
3 < bean class = " org . springframework . web . servlet . view .
InternalResourceViewResolver ">
4 < property name = " prefix " value = " / views / " / >
5 < property name = " suffix " value = " . jsp " / >
6 </ bean >

5.2 What it does


• Scans for @Controller classes.

• Enables annotations (@RequestMapping, etc.).

• Configures how view names map to .jsp files:

– return "result" → /views/result.jsp.

6 Internal Resource View Resolver


6.1 Purpose
• Converts logical view names into physical JSP paths.

• Example:
1 return " result " ;

→ /views/result.jsp (based on prefix/suffix in config).

6.2 Configuration

1 < property name = " prefix " value = " / views / " / >
2 < property name = " suffix " value = " . jsp " / >

Note: Eliminates the need to hardcode .jsp or full paths in controllers.

7 Summary
• Spring MVC: Java web framework based on MVC.

• DispatcherServlet: Front controller that routes requests.

• web.xml: Maps DispatcherServlet and URL patterns.

• telusko-servlet.xml: Configures controller scanning and view resolver.

• Controller: Annotated with @Controller, maps URLs using @RequestMapping.

3
• Model (Alien.java): Simple Java object populated from form data.

• View (JSP): Uses Expression Language ($) to display model data.

• View Resolver: Maps view names (e.g., "result") to /views/result.jsp.

You might also like