Tip:
Highlight text to annotate it
X
Welcome to the first part of the video class on Spring MVC and
jQuery Ajax .
During these video classes I will
teach a little of how
we work with ajax requests
in Java
applications
with Spring MVC
and also, jQuery Ajax.
I going to create an app in Netbeans.
For that, I added in the blog post
a download link, where you
must download
this file,
which contains some files
that
whoud take a little more time to set them during
this video class. So to save a little time, I've
I left these files available
to you.
When I need these files
I will show where we
must added them.
Then, firstly we going to
create a project.
The project is
a maven project.
Then, you need to select the maven option.
Web application.
we will name it as
spring-ajax, ...
okay!
...
Pay attention in this package...
that we created here.
I going to select
Apache Tomcat
JEE 6.
Now, we will finalize and waiting that
the Netbeans
create the project,
to us.
So, the first thing that I going to make,
will be update the dependences
of the maven file.
Thus, we will have access to Spring
and also
to Hibernate Framework
works with database persistence and some other libraries.
For that,
You'll open the pom.xml
file and copy
all dependencies.
...
Now, you'll paste all these dependencies
here ... ... okay!
This is a default dependence that Netbeans added when
we created our project.
It is
Java EE 6, and it'll provide to us the access to the other libraries from
Java EE 6 like,
for example, the part of
Servlets.
For the Spring we will use the spring-context,
the spring-webmvc,
the spring-orm to
use the Hibernate and
the part of transactions, like spring
transaction (spring-tx).
Jacson dependence is important,
it will be...
the communication between
our Ajax requests using jQuery
and the Spring MVC.
The library JSTL,
it will work in our JSP pages..
Here, we have the Hibernate dependencies.
And the MySQL driver, the database connector
that it will added in our project.
We going to save
and close this file.
Now, you going to
web pages...
(I going to close this)
... and we'll add
a new folder
called
WEB-INF.
Return to,
downloaded files and copy
all these files: spring-context, spring-dao, spring-servlet and
web.xml.
After that, paste them
into the WEB-INF folder.
The spring-context is
the responsible file for Spring Framework
initialization.
We will work with annotations, so I add the base package, where
we will put the spring annotations.
In this case,
it will be
com.mballem ...
I think that I had
created the spring ajax package, so I will
update here to spring.ajax
This config will indicate to Spring that we will work with
MVC annotations.
And here we'll import
the files of spring-servlet and spring-dao. Spring-servlet
is the config
to Spring
has access and to work with jsp pages.
In this case, into the WEB-INF folder
we going to create a folder called "views".
This folder will be where our JSP pages
are stored.
So, the Spring going to find all JSP pages
in that folder.
The tag mvc-resource,
will be where I will
add the javascript
file and also the css
file that we'll use
in our JSP pages.
In spring-dao file,
we have configured
the datasource.
You must remind to create the database
in your MySQL GDB.
The database's name is sprig-ajax.
Put here, the password,
But if you already have your Mysql with
another user or password, change here.
The other settings are the
Hibernate.
Nothing
much
different from what you should be accustomed to working with
Spring.
And the SessionFactory,
to finalize, what it is important
for us to work.
I'm using Hibernate 4
to work
with the SessionFactory.
In web.xml file...
... then, we have
the basic settings
from web.xml to work together with Spring, also
nothing much different from the usual.
Into WEB-INF file, we will
create a new folder
called "views".
And here, into web pages
we'll create a page called
"resources", excuse me, this is a folder not a page.
Within of "resources",
we'll create a 'css' folder
and a 'js'
folder.
Within of
'css' folder
paste the file:
style.css.
Then, here has a
css style that we'll use
in our JSP pages.
Now,
we will start to create our Java classes. The first thig that I'll
do is create a package
called 'entity'.
And after a class
called
'Contact'.
So, in the next video classe
we will
continue
developing the Contact class
See you!