Tuesday, July 31, 2007

lab 1

Today's lab had many different parts to it these included:
  • Eclipse
  • Tomcat
  • Spring
  • Ant
  • J2EE and JSP
  • Linux
  • Servlet
  • JSTL
The first part of the lab was easy for me as i have experience with Ant and Eclipse on Linux. However below are some thoughts and things that i should note for later.

Ant provides a tool to deploy, compile and clean the Java app. It serves the same purpose as make with added features. The main part of the Ant program that we deal with is the build.xml file and the build.properties file. These file together provide the deploy, build and clean commands. the properties file gives project specific components such as: location of files. One thing that i noticed is the layout that they want us to use. That is the file layout is different to the one that we would see in normal J2EE apps that i have dealt with before. This is the way that Spring likes it and so we will try to follow it.

The general structure is:
\
|-src
--|bus
--|web
|-war
--|-WEB-INF
----|-jsp
----|-classes
----|-lib
build.xml
build.properties

This is what we will try and keep with.

The next part that was also quite quick was Tomcat. The tomcat file is located in the /opt/tomcat/ folder and is copied to /tmp/tomcat/ at each start up. Tomcat is used in order to deploy our Java app. It does this by using servlets.

The next part was new for me as i have no experience with Spring. Spring is a framework that provides a vast amount of functionality. We use it mainly for the MVC components that it offers. Spring uses servlets in order to perform tasks. So there is a Dispatcher servlet, and a mapping servlet (both which are in our web.xml file)
Once we have this we can form the beans which define the instances of the mapping servlet and dispatcher servlet. This goes into our app specific .xml file. In order to make all this work we require a large amount of extra data in the form of all the libraries. These are copied to our WEB-INF/lib directory and are in the form of JARs.
Spring uses as default the Logger4J app, and so this also is included and written to.

The main issue that we have at this stage is that the model and the view are as one. IN a real MVC app we want the Model and View decoupled. To do this we use a class provided by the Spring framework (InternalResourceViewResolver) . This is instantiated by the use of beans. Doing this decouples the View and Model. and combines them only after the particular view has been resolved.

The business logic is added using simple classes e.g. we use products in order to perform our tasks, these all go into the src file and are split in terms of business logic and web (the controller itself). The controller is an important part as what it does is combine the view and the model, and includes any business logic that is required.
In order to have some data we again use beans to populate our data. This is done in the xml file that controls the app servlet. This is important as it is the app specific things that want to populate this app with certain beans.

The final part of the lab was improving our ant instance with more functionality (again this is easy).

Reflections on what i learnt:

Today i completed Part 1 and Part 2 of the labs. The main concepts and skills i learn was:
  • Use of Spring: how spring works and what you need to do to make it help you
  • The organisation of Spring and what is offers. That is the MVC and the many classes files.
  • Logger 4J interface.
  • Beans as applied to Spring, and MVC.
  • Using Spring to build an app.
The next thing i need to do is make my own app and try not use the files they have given rather then modifying files try and write the sevlets myself. Also try and write some beans.

No comments: