Skip to content

Instantly share code, notes, and snippets.

@nijjwal
Created January 20, 2015 08:04
Show Gist options
  • Save nijjwal/3d14e9c5b4cf8cd9355a to your computer and use it in GitHub Desktop.
Save nijjwal/3d14e9c5b4cf8cd9355a to your computer and use it in GitHub Desktop.
This is my note for spring mvc tutorial from gontuseries.
/**
|---------------------------------------------------------------
|Chapter 3. Installation and setup using Eclipse
|---------------------------------------------------------------
*/
1. Rt click > New > Other > Web > Dynamic Web Project
-Project name: FirstSpringMVCProject
-Next
-Next
-Check "Generate web.xml deployment descriptor"
2. Download spring distribution zip containing all required jars
from this link:
http://repo.spring.io/release/org/springframework/spring/
-Current available version is: 4.1.4 as of Jan 20, 2014
3. Download all jar files manually, dont depend on dependency mechanism
systems to download these jar files. Finally, put them on project's class
path. You can use maven or gradle if you want.
4. Open the extracted zipped file of Spring framework. You will find all
it's required jars in libs directory. Copy all these jar files and paste
it in Project's lib folder.
5. Open Web Content Directory in your project > Web-Inf > lib
-paste all jar files here
6. For loggin purposes, you will need one more jar file to be included in
your lib folder of the project
http://commons.apache.org/proper/commons-logging/download_logging.cgi
I downloaded and copied
commons-logging-1.2.jar file in the lib folder
7. Last but not the least, we need a web server supporting servlet JSP
technology. For example, Apache Tomcat Server, Fish , etc.
8. Step to install Apache Tomacat Server on your computer
-go to the website
http://tomcat.apache.org/download-70.cgi
and download the relevant Tomact Apache Zip for your computer. Select the OS.
B. unizp the contents in your local drive
- Application/Eclipse/apache-tomact-7.0.57
9. Integrate Tomacat Server with the project which you just created. So, that
when you are done with developing the app using MVC framework, you should be
able to run it from Eclipse IDE.
/**
|---------------------------------------------------------------
|Chapter 4. Integrating Tomcat Apache Server with an Eclipse IDE
|---------------------------------------------------------------
*/
1. Windows > Show View > Others > Server > Servers > New Server >
-Click on the link at the bottom that says "No servers are available..."
-Find the Apache Tomact Server V7
2. Finish
3. Rt click on the project and choose properties.
Click on "Targeted Runtimes". And check "Apache Tomcat v7.0"
- Click on "OK"
4. We have succesfully integrated our Project and Tomcat server.
/**
|---------------------------------------------------------------
|Chapter 5. Creating first Spring MVC Application using Eclipse
|---------------------------------------------------------------
*/
1. Create an ultra simple appication using the workflow discussed in chapter 2.
Look at the diagram.
2. Project Detail:
a. User types url in the browser and hits enter
b. Spring Web Application will send back the response to the client browser.
- The response will be simple greeting message.
"Hi User, welcome to our First MVC application"
3. I just need to follow these four simple steps:
a. Modify web.xml file
b. Create spring-dispatcher-servlet.xml
c. Create the HelloController.java class (A controller)
d. Create the HelloPage.jsp file (A view)
4. Modify web.xml file which Eclipse has already generated by default in Web-INF
folder . This file should be placed always under WEB-INF folder of your web project.
The main purpose of this file is to map the url to the servlet that can serve the requet.
- Spring MVC actually using Servlet technolgy as it's base, so you always need to put the
web.xml file in the Web Project developed
- Delete the following code:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
-Add the following code:
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
This code is simply telling the servlet technolgy that all url request to the web application
should be mapped to the spring MVC framework for further processing.
5. Here you are specifically telling the servlet technolgy that once you receive any url request,
map the url request to something called the front controller, also called DispatcherServlet in
the Spring framework. And after that the front controller will take the complete responsibility of
processing the request and sending back the response back to the client's browser with the help of
all it's helpers. That's what in the diagram.
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
@nijjwal
Copy link
Author

nijjwal commented Jan 20, 2015

Contains note for chapter 3,4, and 5. 5 is incomplete right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment