img
Table 17-1. Commonly used Spring MVC Servlet Filters
Filter Class Name
Description
This filter is used to specify the character encoding for
org.springframework.web.filter.Chara
request.
cterEncodingFilter
This filter provides support for HTTP methods other than
org.springframework.web.filter.Hidde
nHttpMethodFilter
GET and POST (for example, PUT).
This filter binds the JPA EntityManager to the thread for the
org.springframework.orm.jpa.support.
OpenEntityManagerInViewFilter
entire processing of the request. It can help restore the same
EntityManager for subsequent requests of the same user so
that JPA features such as lazy fetching will be able to work.
Create the First View in Spring MVC
Having the service layer and Spring MVC configuration in place, we can start to implement our first
view. In this section, we will implement a simple view to display all contacts that were initially populated
by the script test-data.sql.
As mentioned earlier, we will use JSPX to implement the view. JSPX is JSP in well-formed XML
format. The main advantages of JSPX over JSP are as follows:
JPSX forces the separation of code from the view layer more strictly. For example,
·
you can't place Java scriptlets in JSPX document.
Tools might perform instant validation (on the XML syntax), so mistakes can be
·
caught earlier.
JSPX is the recommended format when using JSP with Spring MVC, as well as
·
other Spring projects (Spring Web Flow, Spring Roo, and so on).
To prepare for the first view, one new Maven dependency is required, as listed in Table 17-2. Please
add it to your project.
Table 17-2. Maven Dependencies for Spring MVC View
Group ID
Artifact ID
Version
Description
1.1.1
JSP tag library that support formatting of
joda-time
joda-time-jsptags
Joda Time types in views
Configure the DispatcherServlet
The next step is to configure the DispatcherServlet. To implement this simple view, we need to make
some minor modifications to the default configuration file generated by Spring template project. Listing
17-10 shows the revised configuration (/src/main/webapp/WEB-INF/spring/appServlet/servlet-
context.xml).
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home