13.07.2015 Views

Thesis full text PDF - Politecnico di Milano

Thesis full text PDF - Politecnico di Milano

Thesis full text PDF - Politecnico di Milano

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The Struts ControllerAlthough Struts does not provide or require any particular Model or View components of the MVCpattern, it does implement the Controller as well as the mechanisms that bind the three layersand allow them to communicate with each other. The primary controller class is a Java Servletcalled the ActionServlet. This class handles all user requests for Struts-managed URLs. Usinginformation in the configuration files, the ActionServlet class then gets the appropriateRequestProcessor class that collects the data that is part of the request and puts it into anActionForm, a Bean that contains the data sent from or to the user’s form. The final step of theController is to delegate control to the specific handler of this request type. This handler isalways a subclass of the Action class. Figure 4 shows how Struts uses the MVC pattern. TheAction subclass is the workhorse of the Controller. It looks at the data in the user’s request (nowresi<strong>di</strong>ng in an ActionForm) and determines what action needs to be taken. It may call on thebusiness logic of the Model to perform the action, or it may forward the request to some otherView. The business logic may include interacting with a database or objects across the networkor may simply involve extracting some data from an existing JavaBean. After the necessaryaction has been performed, the Action subclass then chooses the correct View to send back tothe user. The View is determined by the current state of the Model’s data (the model state) andthe specifications you defined in the Struts configuration file. Figure 4.2 shows the principalclasses of the Struts Controller.Figure 4.2 - Struts and MVC patternThe Struts ViewAs mentioned, Struts does not provide, nor is it dependent on, a specific presentationtechnology. Many Struts applications use JSP (JavaServer Pages) along with the Struts taglibrary (Struts and Struts-EL), JSTL (JSP Standard Tag Library), and JSF (Java Server Faces).The JSP specification provides for the creation of HTML-like tags that extend the functionality ofJSP. These custom tags are bundled by their creators into custom tag libraries and are35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!