Simple J2ee Model View Controller Type II Framework

Simple J2EE Model-View-Controller Framework Type II Executive Summary Application is f content? R users in numerous pages containing various data. Also the permission? Professional Engineering team f? R the design, implementation and maintenance of the application of individuals with different F? Skills together. One of the main concerns with the web applications is the separation between the logics that with Pr? Presentation itself, avoiding the data are presented and the one that Str? Determination of programmable logic controllers. It is as a response to these concerns that the Model-View-Controller or MVC pattern was designed. This paper presents the L? Sung f? R the Benutzeroberfl? Che functionality? T to modularize a Web application so that individual parts can k? Easily ge? Be changed, the hey? T Model View Controller Framework. Ins? Channel The Model-View-Controller (MVC) pattern separates the modeling of the cathedral? Ne, the Pr? Presentation, and the actions to user input into three separate classes. Model: The model manages the behavior and data of the Anwendungsdom? Ne, responding to requests f? R information? About its state (usually from the point of view), and responds to instructions to status? Change (usually by the control). Profile: The profile manages the display of information. Controller: The controller interprets the mouse and keyboard input from the user, the information of the model and / or the view? Change, as appropriate. It is important to note that both the view and the controller? About the model from. However, h depends? The model to the view nor the controller. This is one of the main advantages of separation. This separation erm? Created the possibility for the model to be built and tested independently are expecting from the visual Pr? Presentation. The separation between view and controller is, in many rich-client applications, secondary ? ren and in fact, many user interface frameworks implement the roles as an object. In Web applications, on the other hand, the separation between the view (the browser) and controller (the server-side components handling the HTTP request) is defined very well. The L? Solution provided in this paper is very simple plain Servlet and JSP and Java objects to be used very easily with this framework, any kind of real-time applications are k? Can develop. can be understood by following this simple framework most of the complex MVC framework. Model View Controller Types MVC-Type I: In this type of implementation, there is the view and the controller as a unit – the view controller. has implemented a view to implementation, in the Page Centric approach the controller logic within the view ie with J2EE, JSP’s it. All the functions of the controller, such as extraction of HTTP request parameters, invoke the business logic (implemented in Java Beans, if not directly in the JSP), and handling of the HTTP session within APS with jsp scriptlets and action tags embedded. MVC-Type II: The problem with type-I is the lack of maintainability. With controller with embedded logic within the JSP scriptlets, the code can get out of hand very easily. Sun at the problems of maintainability and reusability to overcome? “, The controller logic to be moved in a servlet k? Can and JSP f? R, what should it be used – the View component. Thus by embedding logic within a controller servlet, the type-II MVC design pattern can be implemented. The main difference between MVC type I and type II is where the controller logic in JSP is in Type I and Type-II embedded in its move to servlet. MVC Type-II Framework In this framework, work, model A Plain Old Java Object is a view that will make the JSP page with the model, these two surveilance gt ngig by the application of this framework and avail? Via a central controller is a servlet which the model is bev lkern? and invokes a method from the Action class. Below is the source of the controller. SimpleController. Java Package simple; import java. io. IOException; import java. Lang. . Reflect Method; Javax import. Servlet. ServletException; Import javax. Servlet. http. HttpServlet; Import javax. Servlet. http. HttpServletRequest; Import javax. Servlet. http. HttpServletResponse; public class extends HttpServlet SimpleController ( private ActionBeanMapping mapping; public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException ( try ( StrJsp String = null; String = strURI request. getRequestURI (); int startIndex = strURI. lastIndexOf (“/”); int endIndex = strURI. lastIndexOf (“. do”); Abstract String = strURI. substring (startIndex +1, endIndex); this. populateBean (request, abstraction); SimpleHandler handler = (SimpleHandler) mapping. getActionInstance (abstraction); strJsp = handler. Process (request, response); Request. getRequestDispatcher (strJsp). Forward (request, response); ) Catch (Exception e) ( e. printStackTrace (); Request. getRequestDispatcher (“/ error. jsp”). Forward (request, response); ) ) public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException ( this. doGet (request, response); ) public void init () (throws ServletException String = strFile them. getServletContext (). getRealPath (“/”)+ this. getServletConfig (). getInitParameter (“action mappings”); System. out. println (“Mapping file PATH:” + strFile); try ( Mapping = new ActionBeanMapping (strFile); ) Catch (IOException e) ( e. printStackTrace (); ) ) private void populateBean (HttpServletRequest request, String abstraction) ( Object obj; try ( obj = mapping. getBeanInstance (abstraction); Method methods [] = obj. getClass (). GetMethods (); for (int i = 0; i0) ( Value = strValue array [0]; ) try ( Method. invoke (obj strValue); ) Catch (Exception e) ( e. printStackTrace (); ) ) ) Request. setAttribute (SimpleHandler. BEAN, obj); ) Catch (Exception e) ( e. printStackTrace (); ) ) ) The servlet’s init method is used to initialize the action and bean mapping. public void init () (throws ServletException String = strFile them. getServletContext (). getRealPath (“/”)+ this. getServletConfig (). getInitParameter (“action mappings”); System. out. println (“Mapping file PATH:” + strFile); try ( Mapping = new ActionBeanMapping (strFile); ) Catch (IOException e) ( e. printStackTrace (); ) ) Mapping file path will be taken from the servlet config and initialize the ActionBeanMapping helper class. ActionBeanMapping. Java: Package simple; import java. io. FileInputStream; import java. io. IOException; import java. util. Real estate; public class ActionBeanMapping ( Private Properties prop = new Properties (); ? Public ActionBeanMapping (String propFile) throws IOException ( this. prop. Load (new FileInputStream (propFile)); ) public Object getActionInstance (String location) throws Exception ( String prop = strClass. getProperty (“action.” + action. trim ()); if (strClass == null) throw new NullPointerException (“Null action:” + action); R? ESC to return class. forName (strClass). newInstance (); ) public Object getBeanInstance (String location) throws Exception ( String prop = strClass. getProperty (“bean.” + action); if (strClass == null) throw new NullPointerException (“Null bean:” + action); R? ESC to return class. forName (strClass). newInstance (); ) ) This class reads the properties file and provides two methods to the action and the bean classes using Java reflection to instantiate f? R the action specified by the user. The methods GET and POST of the application calls the following code in the controller. try ( StrJsp String = null; String = strURI request. getRequestURI () int startIndex = strURI. lastIndexOf (“/”); int endIndex = strURI. lastIndexOf (“. do”); Abstract String = strURI. substring (startIndex +1, endIndex); this. populateBean (request, abstraction); SimpleHandler handler = (SimpleHandler) mapping. getActionInstance (abstraction); strJsp = handler. Process (request, response); Request. getRequestDispatcher (strJsp). Forward (request, response); ) Catch (Exception e) ( e. printStackTrace (); Request. getRequestDispatcher (“/ error. jsp”). Forward (request, response); ) This St? Ck Code obtained? Lt the user action from the URI and instantiates the bean and action class, and f? Filled the model and calls the method on a class action. All actions of the classes in the application should implement the interface SimpleHandler. If an error occurs, this controller leads a generic error page. SimpleHandler. Java: Package simple; Import javax. Servlet. http. HttpServletRequest; Import javax. Servlet. http. HttpServletResponse; ? Public interface SimpleHandler ( public static final String bean = “simple. Bean”; public String process (HttpServletRequest request, HttpServletResponse response) throws Exception; ) All classes should implement the action in the application of the process method. Bev lkerungszahl? Model data from the request object is carried by the following controller method? Leads. private void populateBean (HttpServletRequest request, String abstraction) ( Object obj; try ( obj = mapping. getBeanInstance (abstraction); Method methods [] = obj. getClass (). GetMethods (); for (int i = 0; i0) ( Value = strValue array [0]; ) try ( Method. invoke (obj strValue); ) Catch (Exception e) ( e. printStackTrace (); ) ) ) Request. setAttribute (SimpleHandler. BEAN, obj); ) Catch (Exception e) ( e. printStackTrace (); ) ) This method f? Filled, the model data and ties, the model for object request, this model from the action class and JSP is accessed. Error message. jsp [% @ Page language = "java" pageEncoding = "ISO-8859-1"%] [Html] [Head] [Title] Error-page [/ title] [/ Header] [Agent] [Font color = "# ff0000"] [b] Error while processing the request. [/ B] [/ font] [/ Body] [/ Html] The web configuration is defined below, f is a simple configuration file? R controller. web. xml: [? Xml version = "1 0" encoding = "UTF-8"?] [Web-app version = "2 4" xmlns = "http://java. com/xml/ns/j2ee So" xmlns: xsi = "http://www. w3. org/2001/XMLSchema-instance" xsi: schemaLocation = "http://java. This com/xml/ns/j2ee http://java. Sun com/xml/ns/j2ee/web-app_2_4. xsd "] ? [Servlet] ????[ Description] Simple J2EE Controller [/ description] ????[ Display-name] Simple J2EE Controller [/ display-name] ????[ Servlet-name] SimpleController [/ servlet-name] ????[ Servlet-class] simple. SimpleController [/ servlet-class] ????[ Init-param] ????[ Param-name] action mappings [/-param name] ????[ Param-value] WEB-INF/actionmappings. Properties [/ param-value] ????[/ Init-param] ????[ Load-on-startup] 1 [/ load-on-startup] ? [/ Servlet] !! [Servlet-mapping] ????[ Servlet-name] SimpleController [/ servlet-name] ????[ Url-pattern] *. to do [/ url-pattern] ? [/ Servlet-mapping] ? [Welcome-file-list] ????[ Welcome-file] index. jsp [/ welcome-file] ? [/ Welcome-file-list] [/ Web-app] The controller servlet is f? R all URLs that will be called ends with. To do this file servlet L? Dt on server startup, and defines the action mappings way. Example application with the framework Providing sample application for the registration name to save, e-mail and telephone. Index. jsp: [% @ Page language = "java" pageEncoding = "ISO-8859-1"%] [Html] ? [Head] ?? [Title] Home [/ title] ? [/ Header] ? [Agency] ? [Form method = "post" action = register ". Do"] ? [Table width = "200" border = "0" align = "center"] [Tr] [Ad colspan = 2 align = "center"] [strong] UserData [/ strong]

Madhusudan Pagadala is working as a Senior Software Engineer at NetZero, United Online, Inc., in WoodlandHills, California, USA. He has nine years experience in Web technologies like J2EE, HTML, and JavaScript. He pursued Master of Technology in Aerospace Engineering from the prestigious College IIT, Kharagpur, India.

Leave a Reply

Your email address will not be published.


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>