Spring Setup for Time Expression
Now that I have provided you some fundamental concepts for Spring MVC, let’s begin setting it up for development of Time Expression screen.
We need a couple of components to get Spring up and running for us. Figure 7.1 showed the Time Expression high-level architecture we established early in this book. As you can see, we need a servlet container that Spring can run within for our web application. So let’s start with the installation of a Servlet container first, and then we will download and install the Spring Framework.
Installing a Servlet Container (Apache Tomcat)
I have chosen to use Apache Tomcat (http://tomcat.apache.org/) as the Servlet container for the Time Expression application. However, you can use any other product you want; this can be a servlet-container-only product, such as Tomcat, or a full-blown application server, such as JBoss Application Server, BEA WebLogic, or IBM Websphere.Now we can run the ant deploy from a command line using our build.xml file. By running this ant command, a fresh new timex.war web archive file will be built and deployed to the specified directory (in deploy.dir).
Installing the Spring Framework
By now, you should have a thorough understanding of what Spring can do for you. Next, it is time to download Spring, install it, and begin using it!
The Spring Framework can be downloaded from http://springframework.org.We will now follow the instructions provided on the website to download and install it.
The following are one-time setup steps we will need to follow to get Spring set up for our environment. From here, you might add external jars for added Spring functionality as needed to the timex/lib/ directory. (In Chapter 10,“Beyond the Basics,” we will add OpenSymphony’s quartz.jar file to our directory.)
- Spring—Copy spring.jar to the timex/lib/ directory of Time Expression, based on the directory structure we established in Chapter 3,“XP and AMDDBased Architecture and Design Modeling,” and shown here in Figure 7.4.
- JSTL—We also need to obtain JavaServer Pages Standard Tag Library (JSTL), which is part of the Jakarta taglibs project and can be downloaded fromhttp://jakarta.apache.org/taglibs/. After downloading this package, copy the jstl.jar and standard.jar files to the timex/lib/ directory. JSTL helps eliminate (or at least significantly reduces) the amount of embedded scriptlet code in our JSP files. For example, JSTL provides tags for iterations/loops (<forEach>, for example), conditional tags (<if>, for example), formatting tags (fmt:formatDate, for example), and several other tags.You will see examples of many of these tags inthis chapter.
Running Our SpringTest
Incidentally, the three files we discussed in the previous chapter can now be created in the following paths, and we could run ant springtest (from our timex/ top-level directory) to test that we can use Spring in our code.The complete code for these files can be found in this book’s code zip file:
- n src/java/com/visualpatterns/timex/test/SpringTest.java