Spring MVC configuration Tutorial


While recently initiating a project using Spring MVC, we ware trying to discover some technical know how’s. We were doing that at random but one of my friend and college Abdullah Al Hasib made a skeleton project where almost all start-up issues are solved. He also made a documentation for us which further edited by Sheikh Nabil Mohammad also a Friend and college.

I am just including all of this here.

Please Download the project from here
And the sql file from here

Steps:

  1. Create web application with spring frame work.
  2. Edit the beans attribute in dispatcher-servlet.xml file.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

then add in the beans


<!– Scans the classpath of this application for @Components to deploy as beans –>

<context:component-scan base-package=”controller” />

 

<!– Configures the @Controller programming model –>

 

<mvc:annotation-driven />

  1. Now  this project has become anotation based spring web project.


  1. Crate standard packages controller, model, service packages in the source packages where controller stands for receiving all the client request and send response for the corresponding request. Ser vice package is to interect with the database and provide required information to the controller.

Concepts covered in this  Project:
In this project we created some basic example of spring web application such as
1. How to send data to the server by form.
2. How to send data to the server by Ajax.
4. How to send JSON data to the server by Ajax using jquery.
5. How to request to server using anchor (<a href=””></a>).
6. How to use resources such as JavaScript, css, images
7. how to work with basic annotation @Controller , @RequestMapping , @RequestParam , @ResponseBody , @ModelAttribute etc.

Project overview:
1. editStudent.jsp and controller.editStudent() (POST) method provide an example that how to send data to the server using form (<form>).
2. addStudent.jsp and controller.addStudent() method provides an example that how to send data to the server by Ajax.

3. addEmployee.jsp and controller.addEmployee() method provide an example that how to send JSON data to the server using jquery Ajax method.
4. (studentList.jsp and controller.getStudentList() methotd provide an example that how to request server by using anchor (<a href=””></a>)

Note that, we put “resource” folder in the “web Pages” folder. we can put “resource” folder in the “WEB-INF/jsp/” directory but any content in the “WEB INF” folder becomes private. Any content in the “WEB-INF” folder cannot be accessed by the browser that’s why we put “resource” folder in the “web pages” folder out of the “WEB-INF” folder.

Important URL :
1. http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPIntro7.html
2. http://maxheapsize.com/2010/07/20/spring-3-mvc-ajax-and-jquery-magic-or-better-simplicity/
3. http://www.jsptutorial.net/jsp-standard-tag-library-jstl.aspx
4. (*)http://maestric.com/doc/java/spring
5. (***)http://www.raistudies.com/spring/spring-mvc/ajax-spring-mvc-3-annonations-jquery/
6. http://blog.springsource.org/2010/01/25/ajax-simplifications-in-spring-3-0/
7. (***)http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html#mvc-ann-modelattrib

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s