The Application Example
The example is a simple web application that simply demonstrates the integration of components with read/update operations. Its only functions are accepting a user's ID as input, returning the user's profile, and allowing the user to update the profile. While the general instructions to follow are based on using Eclipse, they should apply to other IDEs as well. (The application is available with the downloadable code
First, you need to set up the component model for the application with these steps:
- Create an enterprise J2EE project called Account and create a web project in it called AccountWeb.
- Add the Java EE 5 libraries (javaee5.jar) of your application server to the build path.
- Create a directory called "lib" under the EAR project where you will place all the application JARs. All projects in the EAR will refer to these libraries.
Figure 1 shows the overall component model.
|Figure 1. Overall Component Model:|
Here is the component model for the application example.
Next, you build the presentation tier by creating an index.jsp page and using Spring MVC to hook it up to the appropriate controller and the response page (refer to Figure 1). To complete a standard MVC configuration, add the URL mapping and view resolver to the configuration file springapp-servlet.xml as follows:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
Next, initialize springapp-servlet.xml through the web.xml as follows:
Your web project tree should look like Figure 2 now.
|Figure 2. Web Project Tree:|
Here is how your web project tree should look.
At this point you can transition from the presentation tier to the business tier, where you will implement the business logic for the application example as a stateless session bean.