MVC Model, Struts Framework and File Upload Issues In

MVC Model, Struts Framework and File Upload Issues In

342 MVC Model, Struts Framework and File upload Issues in . Web Applications Based on J2EE Platform -J.Wojciechowski, B.Sakowicz, K.Dura, A. Napieralski Department of Microelectronics and Computer Science, Technical University ofL6dz, Poland Abstract - This paper describes the web application based and control flow. Most Web-tier application frameworks use on the J2EE platform indicating the MVC model, Struts some variation of the MVC design pattern. framework and file upload issues. The development of A Model I architecture [!] [2] consists of a Web internet tech~ology . and the will to standardize the browser directly accessing Web-tier JSP pages. The JSP pages mechanisms used in implementation of internet access Web-tier JavaBeans that represent the application applications was the basis background for the model, and the next view to display is detennined either by development of J2EE platform. hyperlinks selected in the source document or by request The project of International Office TUL internet service is parameters. A Model I application control is decentralized, an application based on the above mentioned because the current page being displayed detennines the next environment. The specification of the project is closely page to display. In addition, each JSP page or servlet connected with the activities and needs of the staff of the processes its own inputs (parameters from GET or POST). International Office. The article presents the use of MVC Such approach is partly implemented in project of model on J2EE platform on an example of open source International Office TUL Internet service. This methodology Apacherfomcat application server and the database of Internet applications management is good for a small management systein MySql. project but whole the structure-background of communication model must be designed by programmer. This technique is for Keywords - MVC, Struts, J2EE, JSP, servlet, file upload, advanced developers. JavaBeans, TO~Cat. , Thin I. INTRODUCTION client The J2EE specification is inseparably connected with the Java language. The solution based on Java 2 platfonn creates a strong, solid, hardware independent base on which one can successfully build systems providing interactive and dynamic Fig. I MVC model I. Internet sites. J2EE is the platfonn working in a multi-layer architecture, , layered set of system services that are A Model 2 architecture [2] introduces a slightly consistently available to J2EE applications across different approach where controller servlet is placed between implementations. The J2EE platfonn runs on top of the J2SE the browser and the JSP pages. The controller centralizes the platfonn, which itself runs. on top of the host operating logic for dispatching requests to the next view, based on the system. In the Web tier, a J2EE Web container provides URL of the request, input parameters, and application state. services related to serving Web requests. The cinly application Model 2 applications are easier to maintain and extend, needed by the client using the system designed according to because views do not refer to each other directly. The Model 2 J2EE standard is a WWW browser. Since the whole system is controller servlet provides a single point of control for located on the server, and not on the clients' computers, new security and logging, and often encapsulates incoming data systems can be upgraded and developed easily and efficiently. into a fonn usable by the back-end MVC model. The Java language with its core features i.e. multitasking and full control upon realizing of applications became the Ill. STRUTS FRAMEWORK infonnal standard for solutions made for web and it also combines heterogeneous applications by means of CORRA. An MVC application framework can greatly simplify JI. MVC -WEB-TIER APPLICATION FRAMEWORK DESIGN implementing a Model 2 application. Application frameworks such as Apache Struts [2] and JavaServer Faces™ a Model-View-Controller ("MVC") is architectural configurable front controller servlet, provide abstract classes design pattern for interactive applications. MVC organizes an that can be extended to handle request dispatches. The key interactive application into three separate modules: one for the scheme is based on servlets for processing requests and application model with its data representation and business selecting views. The Front Controller architectural design logic, the second for views that provide data presentation and pattern centralizes an application's request processing and user input, and the third for a controller to dispatch requests view selection in a single component. Each type of Web client TCSET'2004, February 24-28, 2004, Lviv-Slavsko; Ukraine Authorized licensed use limited to: Chulalongkorn University. Downloaded on June 11,2010 at 10:32:08 UTC from IEEE Xplore. Restrictions apply. 343 sends requests to and receives responses from a single URL, <ihtrnl:form> what simplifies client development. The Front Controller Handling multipart forms is to provide more than one receives requests from the client and dispatches:them to the input of type "file". The first step to create a multipart form is application model. to utilize the struts-html taglib to create the presentation page: In the J2EE platform, a Front Controller is typically implemented as a servlet. The sample application's Front <%@page language="java"> Controller servlet handles all HTTP requests. <%@taglib uri="!WEB-INF!struts-html.tld" . prefix="html "> · THE VIEW: JSP PAGES AND PRESENTATION <html:form action="uploadAction.do"> Please Input Text: The View portion of a Struts-based applicatio~ is most' often constructed· using JavaServer Pages (JSP) <html:text property="myText"><br/> technology. JSP pages can contain static HTML The JSP Please Input The File You Wish to Upload:<br/> environment includes a set of standard action· tags, such as <html:file property="myFile"><br /> <htrnl:submit /> · · <jsp:useBean>. In addition to the built-in actions, there is a standard faciijty to define your own tags, which are organized <ihtml:form> into "custom tag libraries." · · The next step is to create the ActionForm bean: THE MODEL: BUSINESS LOGIC import javax.servlet.http.HttpServletRequest; The model is predominantly the logic of the import javax.servlet.http.HttpServietResponse; application so Struts does not support this since logic depends import org.apache.struts.action.ActionForm; on the purpose of the application. Anyway model should be import org.apache.struts.action.ActionMapping; separated from both layers. It is not very difficult to obtain import org.apache.struts.upload.FonnFile; separation because we can program the model as a single public class UploadForm extends ActionForm { object without focusing on the rest of Internet application. protected String myText; protected FormFile myFile; THE CONTROLLER: ACTIONSERVLET AND ACTIONMAPPING public void setMyText(String text) { The Controller portion of the application is focused myText "" text; on receiving requests from the client (typically a user running l a web browser), deciding what business logic function is to be public String getMyText() { performed, and then delegating responsibility for producing return myText; the next phase of the user interface to an appropriate View l component. In Struts, the primary component of the public void setMyFile(FormFile file) { Controller is a servlet of class ActionServlet · myFile = file; When initialized, the controller parses a } configuration tile (struts-config.xml) and uses it to deploy public FormFile getMyFile() { other control layer objects. Together, these objects form the return my File; Struts Configuration. The Struts Configuration defines ) (among other things) the ActionMappings l [org.apache.struts.action.ActionMappings] for an application. The Struts controller servlet consults the The FormFile class provides the methods to manipulate files ActionMappings as it routes HTTP requests to other in file uploading. To. retrieve the FormFile one should call components in the framework. Often, a request is first method in action class (znowu nie rozumiem!) forwarded to an Action and then to a JSP ( or other ((UploadForm) form).getMyFile(); presentation page). The mappings help the controller tum ,,. HTTP requests into application actions: V. UPLOADING FILES WITH BEAN IV. STRUTS FILE UPLOAD EXAMPLE What org.apache.struts.upload.FormFile does is described below. HTTP request is critical because when you File upload must be started with an HTML form process an uploaded file, you work with raw data obtained including <input> element of type tile, defaulting to the from an HttpServletRequest object's methods such as specified value or the specified property of the bean ServletlnputStream in = request.getlnputStream(); associated with our current form. With the corresponding HTML <input> element, enclosing form element must specify THE CLIENT PART "POST" method attribute, and "multipart/form-data" for the Multipart/form-data defines a new MIME'media type enctype attribute. For example: · . [4] and specifies the behavior of HTML user agents when <htrnl:form method="POST" enctype="multipart/form- interpreting a forrn with enctype="multipart/form-data" or data"> <html:file property="theFile" /> <input type="tile" /> tags. An HTML forrn should have TCSET'2004, February 24-28: 2004, Lviv-Slavsko, Ukraine Authorized licensed use limited to: Chulalongkorn University. Downloaded on June 11,2010 at 10:32:08 UTC from IEEE Xplore. Restrictions apply. 344 enctype

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us