Sunteți pe pagina 1din 5

2008 International Symposium on Information Science and Engieering

Research on Improved MVC Design Pattern Based on Struts and XSL


Shu-qiang Huang Huan-ming Zhang
Network and Educational Technology Center of JiNan University, Guangzhou, China Email:hsq2008@vip.sina.com
Abstract: The MVC design pattern which can weaken the coupling among the different application tiers and make the development and maintenance become simpler, and it has been popularly used in designing web-based J2EE application. Whereas the application scale is larger and larger, traditional MVC pattern exposes some disadvantages. To meet with the development of application, the pattern should be extended and improved. Aiming at some disadvantages of Struts framework, an improved design pattern named XMVC based on Servlet, Bean, XML and XSL was proposed and an application example of the student information management system based on the XMVC pattern was presented in this paper. Key Words: MVC, Struts, XML, XSL, Design pattern

content and it receives data from model and decides the data show form. When model changes, it will notify view to remain the consistency of data; controller is in charge of coordinating actions and events that affect the model and view, it accepts client requests and maps them to implementation actions of model, and returns result to view. In processing of MVC, each client input request is received by controller firstly and controller decides which model to process it; then the model processes the request by business logic; finally view shows result to user by pages [1].

In the development of web applications, the application program was abstracted three distinct parts as model, view and controller by MVC design pattern. To complete the task user has submitted, there are cooperation and division of work among the three parts. The Struts framework provides an implementation for clear separation of business logic and presentation logic, and Web application will be easier to maintain and more extensible. But when the application scale becomes larger, MVC pattern and Struts framework expose some disadvantages [1]. This paper analyses the disadvantage of MVC model and proposes an improved design pattern. I. INTRODUCTION OF MVC PATTERN AND STRUTS
FRAMEWORK Figure 1. MVC model of J2EE

Struts is a framework realization of MVC model. By using MVC model, Struts can be very good to help the java developers to develop J2EE Web application. Like other java structure, Struts is also object-oriented design. In struts, expression logic and business logic is separated fully [2]. The core of Struts framework is a flexible control layer, including Java Servlets, JavaBeans, Resource Bundles and XML technology, and some library of Jakarta Commons. Struts is made up of a group of mutual collaboration classes (components), Servlet and jsp tag lib component. The web application based on struts framework is basically in line with the design standards of JSP Model2, which is an improved design pattern type of traditional MVC. Struts is a realization of MVC and it has inherited all characteristics of MVC and it has made some change and expansion in accordance with the characteristics of J2EE [2]. The working principle of Struts architecture is shown as below:

MVC design pattern is made up of model, View and Controller. The business of application program can be separated, and the task can be distributed clearly by the pattern and the traditional input, processing and output is mapped to three aspects as expression, business and control. In MVC pattern, model is made up of application data and business rules, it is the core of application and controls data access and data update; View is in charge of the expression of model
978-0-7695-3494-7/08 $25.00 2008 IEEE DOI 10.1109/ISISE.2008.252 451

II.

IMPROVED MVC DESIGN PATTERN-XMVC

(1) Advantages and disadvantages of MVC model and Struts framework For most of web applications developed by process language such as ASP or PHP, the initial development
Figure 2. Framework of Struts

template is mixed-layer data programming. For example, client sends requests directly to the database and the result is shown by HTML. Because the separation between data and page is not very direct, it is difficult to reflect the business model or reusability of model. The product developed by traditional pattern is of little flexibility and difficult to meet user demand change. For MVC model, the application is layered and the structure of the product is clear very much, and application of the product can be reflected better by the model. The most important is that multi-view can map to a model in MVC. In the current application, the user demand is changing rapidly and the application should be accessed by different ways. For example, the order model may have different order types, such as system orders, online orders, or orders of other systems, but the processing of different types of orders should be same. In MVC design pattern, the problem can be solved by an order model and several order views. The amount of code reproduction and code maintenance is reduced, and application program can be maintained easily when model changes. MVC is a basic design concept, the understanding of MVC is very easy, but the realization is not very easy. In the course of development, the developer should have excellent analysis ability and design and plan the software structure in detail. If model and view are separated strictly, the debugging will be more difficult but the errors can be found more easily. Experience has shown that the program code mount will increase in MVC when the application is divided into three layers, so the developers should pay more efforts on document management. In conclusion, MVC is a very good basic pattern of developing software, at least business logic and expression logic is separated and the application is divided into three layers constrainedly. if the developers put the additional complexity into consider and the application will be stronger, more extensible, flexible and more personalized[6].

Struts view is realized by JSP mainly, struts includes an extension custom tag library (TagLib), which can simplify the process of creating full international user interface. There are many kinds of tags in current tag library, for example Bean Tags, HTML tags, Logic Tags, Nested Tags, Template Tags, and so on. In Struts architecture, the model is divided into two parts: the system internal state and business logic that is an operation can change the status. Internal state is expressed usually by a group of ActinForm Bean. According to different complexity of design or application, these Bean can be self-contained and has continued state, or access data (from a database) only when necessary. In large-scale applications, business logic is usually encapsulated in the inside of methods, and these methods can be called by bean owning status information. For example, Cart bean has the information users purchase goods and checkout method checks the user credit card and sends order information to storage. In small procedures, operation is a part of controller of struts framework may be embedded in Action class. This approach is suitable when the logic is very simple. It is recommended that user should separate business logical (what to do) and the role Action class plays (how to do). In struts, the basic components of controller are servlet examples of ActionServlet class, and the running servlets are defined by a group of mapping in a configuration file. The business logic operation is completed together mainly by several components including Action, ActionMapping and ActionForward. Action plays the role of realizing business logic; ActionMapping and ActionForward specify running direction of different business logic or process. The controller is configured in the file of struts-config.xml.

452

The development time can be reduced greatly by the tangle of Struts, the maintenance and the expansion will be easier, and it facilitates the team development. ActionForm and Action use inheritance rather than interface, which may reduce the ability expansion and maintenance of application. ActionServlet is single-threaded, there may be threads security issues; the expression layer (View) is realized by JSP mainly, and there are large number of non HTML tags in page files so the edit can not be carried automatically. (2) Improved MVC model-XMVC Aiming at the disadvantages of Struts that the expression layer (View) is realized by JSP and the page files can not be edited automatically, this paper proposes an improved MVC design framework XMVC based on MVC and XML technology.

client browser, then the client browser downloads the XSL according to the path of style sheet, finally the XML will be converted to HTML format [4]. The demand to the client browser of the first method is relatively low and even client browser does not need support for XML. Because all conversion operations are completed on server, server should have a strong ability to process certain requests. For the second method, conversion operation is completed on client browser, and the treatment can reduce the burden on server. But there is a problem that client browser must support XML, and client should have strong processing ability. Taking account of relatively high configuration and strong performance of client system but high costs of server system to meet large number of user access requests, the second method above is more applicable. In the second method, XML and XSL are sent to client browser, and the conversion from XML to HTML is completed on client. The view of Struts is realized by JSP and a large number of non-standard HTML tags are used, so the JSP pages can only be edited manually, which reduces development efficient and makes program maintenance and modification difficult. Using XSL technology, the page design can be realized by general graphical page design tools and a HTML document can be converted to a XML document only by modifying a small amount of code. So this design is intuitive and efficient and also facilitates the modification and maintenance. XML is a simple and standard approach of raw data exchange between programs. it fundamentally has solved the information exchange between application systems. Because XML meet two basic needs of information exchange: data and expression are separated and data is transmitted between different applications. In order to make data suitable for different applications, there should be a way that can convert a data format to any kind of data formats, such as the demanded format may be a text file, a SQL statement, a HTTP document, or other data. XSLT is a language that can realize data format conversion, and it is used not only to convert XML format to HTML

Figure 3. Improved MVC model-XMVC

The controller of XMVC is made up of many Servlets. It receives HTTP Request from client browser, and then calls different Bean to complete the relevant business operation in accordance with different requests, finally a combination of XML string and XSL file is send back to client browser from Bean[3]. The model of XMVC is made up of many Beans. it receives the call of Servlet and completes relative business logic. If the model needs to return data, the data will be organized a XML string and returned to Servlet. A HTML page can be build by two different methods by the combination technology of XML and XSL. One method is that XML and XSL (eXtensible Stylesheet Language), are input to XSLT (eXtensible Stylesheet Language Transformation) server processor and HTML format is output, and then the HTML format will be sent to client browser. Another method is that the path of XSL is added into XML as style sheet element and the XML is sent to

453

format and text format, in nature XSLT is a language converting the structure of XML document. III. STUDENT INFORMATION SYSTEM DESIGN BASED ON XMVC Based on the XMVC design framework, the author has developed a student management system and the experiment has shown that XMVC framework is applicable and effective. The student information management system should realize the functions as the follow: student information management, teacher information management, major information management, course information management and examination score management. The system is made up of five models including student information management model, teacher information management model, major information model. (1) The controller design of student management system The controller is made up of some Java Servlets. The controller plays the role of receiving adding, deleting, querying and modifying operation requests all kinds of information, then calls business logic class (bean) to complete the relevant operation, finally returns the operation results to users. The user fills out a form in the browser and submits request to server, the controller calls business logic based on user request and returns results to user. StudentInfoMag is in charge of implementing the operation request control about student related information, and assigning task to StuInfoMagBean, the final operation results will be returned to user. TeacherInfoMag is in charge of implementation the operation request control about teacher-related information, and assigning task to TeacherInfoMagBean, the final operation results will be returned to user. Like StudentInfoMag and TeacherInfoMag, MajorInfoMag, CourseInfoMag and ScoreInfoMag finish homologous function. The controller input request from client browser is obtained by HttpServletRequest object of server, and the management model, course information management model and score information management

program implements related task in accordance with different request type value cmdACT.

Figure 4.

Mapping between cmdCAT and operation type

Other input items are all kinds of information table fields. The system receives information including field by class formBean. The output of controller is XML document flow. The controller calls different types of business logic (bean) in accordance with request, and the business logic implements related operation and returns a XML string, the controller adds XSL to the XML string, at last the XML document flow is sent to client and shown on browser. The interface of controller about MajorInfoMag is as following:

Figure 5.

Interface of MajorInfoMag

And the correlative data structure between model and entity of is as following:

Figure6. The relevancy between model and entity

(2) The model design of student management system Business logic class plays the role of model in the MVC. Business logic class accepts the call of controller and completes the related operations, and the last returns the operating results including a string of XML to controller. There are three data input types of business logic class.

454

a. database connection Database connection is generated by controller. When controller calls business logic class, it must send a database connection parameter to business logic class, and the business logic will complete the database related operations by the database connection parameter. b. table field class Table field data class is a Java Bean, and each table field data class is mapping with a table and contains getter and setter method of table field [5]. The controller writes field information to table filed data class by setter method and the business logic reads information from table field class by getter method. c. extra condition data When identify the record should be updated, some extra condition information should be given, and the condition information is the primary key information in general. The business logic returns different results according to different operations. If the operation is query, the business logic will return a XML string; if the operation is adding, deleting or modifying, the business logic will return true or false. The interface of model about

Table field data class is an assistant class, the class can help controller send data to business logic. When a table has many basic information fields, if the field information is transmitted as parameters of method, it means the definition of method will be very long, but also prone to error. By table field class, the method call will be simplified and the mistakes can be avoided. IV. CONCLUSION

This paper studied some question about MVC model and Struts framework, and put forwards a new XMVC framework based on traditional MVC and XSLT technology. A web application example developed by XMVC framework was introduced and the experiment has shown that the development by XMVC is more efficient and the application is more extensible and maintainable. ACKNOWLEDGMENT Research of the authors was supported Guangdong Province Science and Technology Plan Programs (No.2006B15401002 and 2006B15001008). REFERENCES
[1]Avraham Leff, James T. Rayfield,Web-Application Development Using the Model/View/Controller Design Pattern, Proceedings of the 5th IEEE International Conference on Enterprise Distributed Object

StudentInfoMagBean is as following:

Computing,2001 [2] J Wojciechowski, B Sakowicz, MVC model, struts framework and file upload issues in web applications based on J2EE platform, Modern Problems of Radio Engineering, Telecommunications and Computer Science Proceedings of the International Conference, 2004. [3] J Shanmugasundaram, E Shekita, Efficiently Publishing Relational Figure7. Interface of StudentInfoMagBean Data as XML Documents, The VLDB Journal the International Journal on Very Large Data Bases, 2001 [4] G Gottlob, C Koch ,XPath Query Processing, LECTURE NOTES IN COMPUTER SCIENCE, 2004. [5] Richard Cardone, Danny Soroker, Using XForms to simplify Web programming, Proceedings of the 14th international conference on World Wide Web,2005 [6] D Schnelle, T Klug, Applying the MVC Pattern to Generated User Interfaces with a Focus on Audio, LECTURE NOTES IN COMPUTER Figure8. The relevancy between Bean and table SCIENCE, 2007.

And the correlative data structure between Bean and table information of is as following:

(3) The table field class design

455

S-ar putea să vă placă și