Recent Edits
h1. "Struts Quiz ":http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs.php.
A framework...
» complete changeStruts is hosted by the Apache Software Foundation (ASF) as part of its Jakarta project. The framework is called āStrutsā to remind us of the invisible underpinnings that hold up our houses, buildings, bridges, and, indeed, ourselves when we are on stilts. This is an excellent description of the role Struts plays in developing web applications. When raising physical structures, construction engineers use struts to provide support for each floor of a building. Likewise, software engineers use Struts to support each layer of a business application.
h1. "Struts Quiz ":http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs.php.
1 What are application frameworks?
A framework is a reusable, semi-complete application that can be specialized to produce custom applications . Like people, software applications are more alike than they are different. They run on the reresame computers, expect input from the same devices, output to the same displays, and save data to the same hard disks. Developers working on conventional desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Application frameworks build on this common ground to provide developers with a reusable structure that can serve as the foundation for their own products. A framework provides developers with a set of backbone components that have the following characteristics:
_ They are known to work well in other applications.
_ They are ready to use with the next project.
_ They can also be used by other teams in the organization.
Frameworks are the classic build-versus-buy proposition. If you build it, you will understand it when you are doneābut how long will it be before you can roll your own? If you buy it, you will have to climb the learning curveāand how long is that going to take? There is no right answer here, but most observers would agree that frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially for larger projects.
2. Enabling technologies
Applications developed with Struts are based on a number of enabling technologies. These components are not specific to Struts and underlie every Java web application. A reason that developers use frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP.
2.1 Java servlets
Sunās Java Servlet platform directly addresses the two main drawbacks of CGI programs.
First, servlets offer better performance and utilization of resources than conventional CGI programs. Second, the write-once, run-anywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM). A servlet looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications. The servlet itself is simply a Java class that has been compiled into byte code, like any other Java object. The servlet has access to a rich API of HTTP-specific services, but it is still just another Java object running in an application and can leverage all your other Java assets. To give conventional web servers access to servlets, the servlets are plugged into containers. The servlet container is attached to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes the servlet. But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs.Once the servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init() method to hold references to expensive resources, such as database connections or EJB Home Interfaces,so that they can be shared between requests. Acquiring resources like these can take several secondsāwhich is longer than many surfers are willing to wait. The other edge of the sword is that, since servlets are multithreaded, servlet developers must take special care to be sure their servlets are thread-safe. To learn more about servlet programming, we recommend Java Servlets by Example, by AlanR. Williamson. The definitive source for Servlet information is the Java Servlet Specification.
2.2 JavaServer Pages
While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developers are still stuck with using println statements to render the HTML.That is all too common in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more complex, Java developers end up being cast into the role of HTML page designers. Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, making it difficult for team members to specialize.To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a single component. To build Java-Server Pages, developers start by creating HTML pages in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page. Scripting elements are tags that encapsulate logic that is recognized by the JSP. You can easily pick out scripting elements on JSP pages by looking for code that begins with <% and ends with %>. There are three different types of scripting elements: expressions, scriptlets, and DeclarationsćTo be seen as a JSP page, the file just needs to be saved with an extension of .jsp. When a client requests the JSP page, the container translates the page into a source code file for a Java servlet and compiles the source into a Java class fileā just as you would do if you were writing a servlet from scratch. At runtime, the container can also check the last modified date of the JSP file against the class file. If the JSP file has changed since it was last compiled, the container will retranslate and rebuild the page all over again. Project managers can now assign the presentation layer to HTML developers, who then pass on their work to Java developers to complete the business-logic portion. The important thing to remember is that a JSP page is really just a servlet. Anything you can do with a servlet, you can do with a JSP.
2.3 JavaBeans
JavaBeans are Java classes which conform to a set of design patterns that make them easier to use with development tools and other components. DEFINITION A JavaBean is a reusable software component written in Java. To qualify as a JavaBean, the class must be concrete and public, and have a noargument constructor. JavaBeans expose internal fields as properties by providing public methods that follow a consistent design pattern. Knowing that the property names follow this pattern, other Java classes are able to use introspection to discover and manipulate JavaBean properties.The JavaBean design patterns provide access to the beanās internal state through two flavors of methods: accessors are used to read a JavaBeanās state; mutators are used to change a JavaBeanās state. Mutators are always prefixed with lowercase token set followed by the property name. The first character in the property name must be uppercase. The return value is always voidāmutators only change property values; they do not retrieve them. The mutator for a simple property takes only one parameter in its signature, which can be of any type. Mutators are often nicknamed setters after their prefix. A similar design pattern is used to create the accessor method signature. Accessor methods are always prefixed with the lowercase token get, followed by the property name. The first character in the property name must be uppercase. The return value will match the method parameter in the corresponding mutator.Accessors for simple properties cannot accept parameters in their method signature. Not surprisingly, accessors are often called getters. If the accessor returns a logical value, there is a variant pattern. Instead of using the lowercase token get, a logical property can use the prefix is, followed by the property name. The first character in the property name must be uppercase. The return value will always be a logical valueāeither boolean or Boolean. Logical accessors cannot accept parameters in their method signature. The canonical method signatures play an important role when working with Java-Beans. Other components are able to use the Java Reflection API to discover a JavaBeanās properties by looking for methods prefixed by set, is, or get. If a component finds such a signature on a JavaBean, it knows that the method can be used to access or change the beanās properties. Sun introduced JavaBeans to work with GUI components, but they are now used with every aspect of Java development, including web applications. When Sun engineers developed the JSP tag extension classes, they designed them to work with JavaBeans. The dynamic data for a page can be passed as a JavaBean, and the JSP tag can then use the beanās properties to customize the output.
3 Model 2
The 0.92 release of the Servlet/JSP Specification described Model 2 as an architecture that uses servlets and JSP pages together in the same application. The term Model 2 disappeared from later releases, but it remains in popular use among Java web developers. Under Model 2, servlets handle the data access and navigational flow, while JSP pages handle the presentation. Model 2 lets Java engineers and HTML developers each work on their own part of the application. A change in one part of a Model 2 application does not mandate a change to another part of the application. HTML developers can often change the look and feel of an application without changing how the back-office servlets work. The Struts framework is based on the Model 2 architecture. It provides a controller servlet to handle the navigational flow and special classes to help with the data access. A substantial custom tag library is bundled with the framework to make Struts easy to use with JSP pages.
4 Struts controller components
The Struts controller is a set of programmable components that allow developers to define exactly how their application interacts with the user. These components hide nasty, cumbersome implementation details behind logical names. Developers can program these details once, then go back to thinking in terms of what the program does rather than how it does it. Users interact with a web application through hyperlinks and HTML forms. The hyperlinks lead to pages that display data and other elements, such as text and images.
4.1 Hyperlinks
To the application developer, a hyperlink is a path to some resource in the application. This may be a web page or a custom action. It may also include special parameters. In Struts, these objects have a logical name and a path property. This lets developers set the path and then refer to the ActionForward by name. ActionForwards are usually defined in an XML configuration file that Struts reads when the web application loads. Struts uses the XML definitions to create the Struts configuration, which includes a list of ActionForwards.
4.2 HTML forms
The web protocols, HTTP and HTML, provide a mechanism for submitting data from a form but leave receiving the data as an exercise for the developer. The Struts framework provides an ActionForm class, which is designed to handle input from an HTML form, validate the input, and redisplay the form to the user for correction (when needed), along with any corresponding prompts or messages. ActionForms are just JavaBeans with a couple of standard methods to manage the validation and revision cycle.Struts utomatically matches the JavaBean properties with the attributes of the HTML controls. The developer defines the Action-Form class. Struts does the rest.This class will automatically populate the username field from a form with an HTML form element of the same name.
4.3 Custom actions
An HTML form uses an action parameter to tell the browser where to send the formās data. The Struts framework supplies a corresponding Action class to receive such data. The framework automatically creates, populates, validates, and finally passes the appropriate ActionForm to the Action object. The Action can then get the data it needs directly from the ActionForm bean. An Action concludes by returning an ActionForward object to the controller. This allows the Action to choose a definition using logical names, like continue or cancel, rather than system paths. To ensure extensibility, the controller also passes the current request and response object. In practice, an Action can do anything a Java Servlet can do. In addition to the ActionForward, ActionForm, and Action objects, the Struts controller layer provides several other specialized components, including Action- Mappings and the ActionServlet. Struts also supports localizing your application from the controller layer.
4.4 ActionMappings
In a web application, every resource must be referred to through a Uniform Resource Identifier (URI). This includes HTML pages, JSP pages, and any custom actions. To give the custom Actions a URI, or path, the Struts framework provides an ActionMapping object. Like the ActionForwards and ActionForms, the Actionmapping usually defined in the XML configuration file. This also allows the same Action object to be used by different mappings. For example, one mapping may require validation; another may not.
4.5 ActionServlet
The Struts ActionServlet works quietly behind the scenes, binding the other components together. Although it can be subclassed, most Struts 1.0 developers treat the ActionServlet as a blackbox: they configure it and leave it alone
4.6 Localization
Web applications also interact with users through prompts and messages. The Struts components have localization features built in so that applications can be written for an international audience.
Thanks
h1. "Struts Quiz ":http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs.php.
A framework...
» complete changeStruts is hosted by the Apache Software Foundation (ASF) as part of its Jakarta project. The framework is called āStrutsā to remind us of the invisible underpinnings that hold up our houses, buildings, bridges, and, indeed, ourselves when we are on stilts. This is an excellent description of the role Struts plays in developing web applications. When raising physical structures, construction engineers use struts to provide support for each floor of a building. Likewise, software engineers use Struts to support each layer of a business application.
h1. "Struts Quiz ":http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs.php.
1 What are application frameworks?
A framework is a reusable, semi-complete application that can be specialized to produce custom applications . Like people, software applications are more alike than they are different. They run on the reresame computers, expect input from the same devices, output to the same displays, and save data to the same hard disks. Developers working on conventional desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Application frameworks build on this common ground to provide developers with a reusable structure that can serve as the foundation for their own products. A framework provides developers with a set of backbone components that have the following characteristics:
_ They are known to work well in other applications.
_ They are ready to use with the next project.
_ They can also be used by other teams in the organization.
Frameworks are the classic build-versus-buy proposition. If you build it, you will understand it when you are doneābut how long will it be before you can roll your own? If you buy it, you will have to climb the learning curveāand how long is that going to take? There is no right answer here, but most observers would agree that frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially for larger projects.
2. Enabling technologies
Applications developed with Struts are based on a number of enabling technologies. These components are not specific to Struts and underlie every Java web application. A reason that developers use frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP.
2.1 Java servlets
Sunās Java Servlet platform directly addresses the two main drawbacks of CGI programs.
First, servlets offer better performance and utilization of resources than conventional CGI programs. Second, the write-once, run-anywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM). A servlet looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications. The servlet itself is simply a Java class that has been compiled into byte code, like any other Java object. The servlet has access to a rich API of HTTP-specific services, but it is still just another Java object running in an application and can leverage all your other Java assets. To give conventional web servers access to servlets, the servlets are plugged into containers. The servlet container is attached to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes the servlet. But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs.Once the servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init() method to hold references to expensive resources, such as database connections or EJB Home Interfaces,so that they can be shared between requests. Acquiring resources like these can take several secondsāwhich is longer than many surfers are willing to wait. The other edge of the sword is that, since servlets are multithreaded, servlet developers must take special care to be sure their servlets are thread-safe. To learn more about servlet programming, we recommend Java Servlets by Example, by AlanR. Williamson. The definitive source for Servlet information is the Java Servlet Specification.
2.2 JavaServer Pages
While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developers are still stuck with using println statements to render the HTML.That is all too common in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more complex, Java developers end up being cast into the role of HTML page designers. Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, making it difficult for team members to specialize.To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a single component. To build Java-Server Pages, developers start by creating HTML pages in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page. Scripting elements are tags that encapsulate logic that is recognized by the JSP. You can easily pick out scripting elements on JSP pages by looking for code that begins with <% and ends with %>. There are three different types of scripting elements: expressions, scriptlets, and DeclarationsćTo be seen as a JSP page, the file just needs to be saved with an extension of .jsp. When a client requests the JSP page, the container translates the page into a source code file for a Java servlet and compiles the source into a Java class fileā just as you would do if you were writing a servlet from scratch. At runtime, the container can also check the last modified date of the JSP file against the class file. If the JSP file has changed since it was last compiled, the container will retranslate and rebuild the page all over again. Project managers can now assign the presentation layer to HTML developers, who then pass on their work to Java developers to complete the business-logic portion. The important thing to remember is that a JSP page is really just a servlet. Anything you can do with a servlet, you can do with a JSP.
2.3 JavaBeans
JavaBeans are Java classes which conform to a set of design patterns that make them easier to use with development tools and other components. DEFINITION A JavaBean is a reusable software component written in Java. To qualify as a JavaBean, the class must be concrete and public, and have a noargument constructor. JavaBeans expose internal fields as properties by providing public methods that follow a consistent design pattern. Knowing that the property names follow this pattern, other Java classes are able to use introspection to discover and manipulate JavaBean properties.The JavaBean design patterns provide access to the beanās internal state through two flavors of methods: accessors are used to read a JavaBeanās state; mutators are used to change a JavaBeanās state. Mutators are always prefixed with lowercase token set followed by the property name. The first character in the property name must be uppercase. The return value is always voidāmutators only change property values; they do not retrieve them. The mutator for a simple property takes only one parameter in its signature, which can be of any type. Mutators are often nicknamed setters after their prefix. A similar design pattern is used to create the accessor method signature. Accessor methods are always prefixed with the lowercase token get, followed by the property name. The first character in the property name must be uppercase. The return value will match the method parameter in the corresponding mutator.Accessors for simple properties cannot accept parameters in their method signature. Not surprisingly, accessors are often called getters. If the accessor returns a logical value, there is a variant pattern. Instead of using the lowercase token get, a logical property can use the prefix is, followed by the property name. The first character in the property name must be uppercase. The return value will always be a logical valueāeither boolean or Boolean. Logical accessors cannot accept parameters in their method signature. The canonical method signatures play an important role when working with Java-Beans. Other components are able to use the Java Reflection API to discover a JavaBeanās properties by looking for methods prefixed by set, is, or get. If a component finds such a signature on a JavaBean, it knows that the method can be used to access or change the beanās properties. Sun introduced JavaBeans to work with GUI components, but they are now used with every aspect of Java development, including web applications. When Sun engineers developed the JSP tag extension classes, they designed them to work with JavaBeans. The dynamic data for a page can be passed as a JavaBean, and the JSP tag can then use the beanās properties to customize the output.
3 Model 2
The 0.92 release of the Servlet/JSP Specification described Model 2 as an architecture that uses servlets and JSP pages together in the same application. The term Model 2 disappeared from later releases, but it remains in popular use among Java web developers. Under Model 2, servlets handle the data access and navigational flow, while JSP pages handle the presentation. Model 2 lets Java engineers and HTML developers each work on their own part of the application. A change in one part of a Model 2 application does not mandate a change to another part of the application. HTML developers can often change the look and feel of an application without changing how the back-office servlets work. The Struts framework is based on the Model 2 architecture. It provides a controller servlet to handle the navigational flow and special classes to help with the data access. A substantial custom tag library is bundled with the framework to make Struts easy to use with JSP pages.
4 Struts controller components
The Struts controller is a set of programmable components that allow developers to define exactly how their application interacts with the user. These components hide nasty, cumbersome implementation details behind logical names. Developers can program these details once, then go back to thinking in terms of what the program does rather than how it does it. Users interact with a web application through hyperlinks and HTML forms. The hyperlinks lead to pages that display data and other elements, such as text and images.
4.1 Hyperlinks
To the application developer, a hyperlink is a path to some resource in the application. This may be a web page or a custom action. It may also include special parameters. In Struts, these objects have a logical name and a path property. This lets developers set the path and then refer to the ActionForward by name. ActionForwards are usually defined in an XML configuration file that Struts reads when the web application loads. Struts uses the XML definitions to create the Struts configuration, which includes a list of ActionForwards.
4.2 HTML forms
The web protocols, HTTP and HTML, provide a mechanism for submitting data from a form but leave receiving the data as an exercise for the developer. The Struts framework provides an ActionForm class, which is designed to handle input from an HTML form, validate the input, and redisplay the form to the user for correction (when needed), along with any corresponding prompts or messages. ActionForms are just JavaBeans with a couple of standard methods to manage the validation and revision cycle.Struts utomatically matches the JavaBean properties with the attributes of the HTML controls. The developer defines the Action-Form class. Struts does the rest.This class will automatically populate the username field from a form with an HTML form element of the same name.
4.3 Custom actions
An HTML form uses an action parameter to tell the browser where to send the formās data. The Struts framework supplies a corresponding Action class to receive such data. The framework automatically creates, populates, validates, and finally passes the appropriate ActionForm to the Action object. The Action can then get the data it needs directly from the ActionForm bean. An Action concludes by returning an ActionForward object to the controller. This allows the Action to choose a definition using logical names, like continue or cancel, rather than system paths. To ensure extensibility, the controller also passes the current request and response object. In practice, an Action can do anything a Java Servlet can do. In addition to the ActionForward, ActionForm, and Action objects, the Struts controller layer provides several other specialized components, including Action- Mappings and the ActionServlet. Struts also supports localizing your application from the controller layer.
4.4 ActionMappings
In a web application, every resource must be referred to through a Uniform Resource Identifier (URI). This includes HTML pages, JSP pages, and any custom actions. To give the custom Actions a URI, or path, the Struts framework provides an ActionMapping object. Like the ActionForwards and ActionForms, the Actionmapping usually defined in the XML configuration file. This also allows the same Action object to be used by different mappings. For example, one mapping may require validation; another may not.
4.5 ActionServlet
The Struts ActionServlet works quietly behind the scenes, binding the other components together. Although it can be subclassed, most Struts 1.0 developers treat the ActionServlet as a blackbox: they configure it and leave it alone
4.6 Localization
Web applications also interact with users through prompts and messages. The Struts components have localization features built in so that applications can be written for an international audience.
Thanks
h1. "Struts Quiz ":http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs.php.
A framework...
Struts is hosted by the Apache Software Foundation (ASF) as part of its Jakarta project. The framework is called āStrutsā to remind us of the invisible underpinnings that hold up our houses, buildings, bridges, and, indeed, ourselves when we are on stilts. This is an excellent description of the role Struts plays in developing web applications. When raising physical structures, construction engineers use struts to provide support for each floor of a building. Likewise, software engineers use Struts to support each layer of a business application.
h1. "Struts Quiz ":http://www.developersbook.com/struts/interview-questions/struts-interview-questions-faqs.php.
1 What are application frameworks?
A framework is a reusable, semi-complete application that can be specialized to produce custom applications . Like people, software applications are more alike than they are different. They run on the reresame computers, expect input from the same devices, output to the same displays, and save data to the same hard disks. Developers working on conventional desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Application frameworks build on this common ground to provide developers with a reusable structure that can serve as the foundation for their own products. A framework provides developers with a set of backbone components that have the following characteristics:
_ They are known to work well in other applications.
_ They are ready to use with the next project.
_ They can also be used by other teams in the organization.
Frameworks are the classic build-versus-buy proposition. If you build it, you will understand it when you are doneābut how long will it be before you can roll your own? If you buy it, you will have to climb the learning curveāand how long is that going to take? There is no right answer here, but most observers would agree that frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially for larger projects.
2. Enabling technologies
Applications developed with Struts are based on a number of enabling technologies. These components are not specific to Struts and underlie every Java web application. A reason that developers use frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP.
2.1 Java servlets
Sunās Java Servlet platform directly addresses the two main drawbacks of CGI programs.
First, servlets offer better performance and utilization of resources than conventional CGI programs. Second, the write-once, run-anywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM). A servlet looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications. The servlet itself is simply a Java class that has been compiled into byte code, like any other Java object. The servlet has access to a rich API of HTTP-specific services, but it is still just another Java object running in an application and can leverage all your other Java assets. To give conventional web servers access to servlets, the servlets are plugged into containers. The servlet container is attached to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes the servlet. But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs.Once the servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init() method to hold references to expensive resources, such as database connections or EJB Home Interfaces,so that they can be shared between requests. Acquiring resources like these can take several secondsāwhich is longer than many surfers are willing to wait. The other edge of the sword is that, since servlets are multithreaded, servlet developers must take special care to be sure their servlets are thread-safe. To learn more about servlet programming, we recommend Java Servlets by Example, by AlanR. Williamson. The definitive source for Servlet information is the Java Servlet Specification.
2.2 JavaServer Pages
While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developers are still stuck with using println statements to render the HTML.That is all too common in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more complex, Java developers end up being cast into the role of HTML page designers. Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, making it difficult for team members to specialize.To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a single component. To build Java-Server Pages, developers start by creating HTML pages in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page. Scripting elements are tags that encapsulate logic that is recognized by the JSP. You can easily pick out scripting elements on JSP pages by looking for code that begins with <% and ends with %>. There are three different types of scripting elements: expressions, scriptlets, and DeclarationsćTo be seen as a JSP page, the file just needs to be saved with an extension of .jsp. When a client requests the JSP page, the container translates the page into a source code file for a Java servlet and compiles the source into a Java class fileā just as you would do if you were writing a servlet from scratch. At runtime, the container can also check the last modified date of the JSP file against the class file. If the JSP file has changed since it was last compiled, the container will retranslate and rebuild the page all over again. Project managers can now assign the presentation layer to HTML developers, who then pass on their work to Java developers to complete the business-logic portion. The important thing to remember is that a JSP page is really just a servlet. Anything you can do with a servlet, you can do with a JSP.
2.3 JavaBeans
JavaBeans are Java classes which conform to a set of design patterns that make them easier to use with development tools and other components. DEFINITION A JavaBean is a reusable software component written in Java. To qualify as a JavaBean, the class must be concrete and public, and have a noargument constructor. JavaBeans expose internal fields as properties by providing public methods that follow a consistent design pattern. Knowing that the property names follow this pattern, other Java classes are able to use introspection to discover and manipulate JavaBean properties.The JavaBean design patterns provide access to the beanās internal state through two flavors of methods: accessors are used to read a JavaBeanās state; mutators are used to change a JavaBeanās state. Mutators are always prefixed with lowercase token set followed by the property name. The first character in the property name must be uppercase. The return value is always voidāmutators only change property values; they do not retrieve them. The mutator for a simple property takes only one parameter in its signature, which can be of any type. Mutators are often nicknamed setters after their prefix. A similar design pattern is used to create the accessor method signature. Accessor methods are always prefixed with the lowercase token get, followed by the property name. The first character in the property name must be uppercase. The return value will match the method parameter in the corresponding mutator.Accessors for simple properties cannot accept parameters in their method signature. Not surprisingly, accessors are often called getters. If the accessor returns a logical value, there is a variant pattern. Instead of using the lowercase token get, a logical property can use the prefix is, followed by the property name. The first character in the property name must be uppercase. The return value will always be a logical valueāeither boolean or Boolean. Logical accessors cannot accept parameters in their method signature. The canonical method signatures play an important role when working with Java-Beans. Other components are able to use the Java Reflection API to discover a JavaBeanās properties by looking for methods prefixed by set, is, or get. If a component finds such a signature on a JavaBean, it knows that the method can be used to access or change the beanās properties. Sun introduced JavaBeans to work with GUI components, but they are now used with every aspect of Java development, including web applications. When Sun engineers developed the JSP tag extension classes, they designed them to work with JavaBeans. The dynamic data for a page can be passed as a JavaBean, and the JSP tag can then use the beanās properties to customize the output.
3 Model 2
The 0.92 release of the Servlet/JSP Specification described Model 2 as an architecture that uses servlets and JSP pages together in the same application. The term Model 2 disappeared from later releases, but it remains in popular use among Java web developers. Under Model 2, servlets handle the data access and navigational flow, while JSP pages handle the presentation. Model 2 lets Java engineers and HTML developers each work on their own part of the application. A change in one part of a Model 2 application does not mandate a change to another part of the application. HTML developers can often change the look and feel of an application without changing how the back-office servlets work. The Struts framework is based on the Model 2 architecture. It provides a controller servlet to handle the navigational flow and special classes to help with the data access. A substantial custom tag library is bundled with the framework to make Struts easy to use with JSP pages.
4 Struts controller components
The Struts controller is a set of programmable components that allow developers to define exactly how their application interacts with the user. These components hide nasty, cumbersome implementation details behind logical names. Developers can program these details once, then go back to thinking in terms of what the program does rather than how it does it. Users interact with a web application through hyperlinks and HTML forms. The hyperlinks lead to pages that display data and other elements, such as text and images.
4.1 Hyperlinks
To the application developer, a hyperlink is a path to some resource in the application. This may be a web page or a custom action. It may also include special parameters. In Struts, these objects have a logical name and a path property. This lets developers set the path and then refer to the ActionForward by name. ActionForwards are usually defined in an XML configuration file that Struts reads when the web application loads. Struts uses the XML definitions to create the Struts configuration, which includes a list of ActionForwards.
4.2 HTML forms
The web protocols, HTTP and HTML, provide a mechanism for submitting data from a form but leave receiving the data as an exercise for the developer. The Struts framework provides an ActionForm class, which is designed to handle input from an HTML form, validate the input, and redisplay the form to the user for correction (when needed), along with any corresponding prompts or messages. ActionForms are just JavaBeans with a couple of standard methods to manage the validation and revision cycle.Struts utomatically matches the JavaBean properties with the attributes of the HTML controls. The developer defines the Action-Form class. Struts does the rest.This class will automatically populate the username field from a form with an HTML form element of the same name.
4.3 Custom actions
An HTML form uses an action parameter to tell the browser where to send the formās data. The Struts framework supplies a corresponding Action class to receive such data. The framework automatically creates, populates, validates, and finally passes the appropriate ActionForm to the Action object. The Action can then get the data it needs directly from the ActionForm bean. An Action concludes by returning an ActionForward object to the controller. This allows the Action to choose a definition using logical names, like continue or cancel, rather than system paths. To ensure extensibility, the controller also passes the current request and response object. In practice, an Action can do anything a Java Servlet can do. In addition to the ActionForward, ActionForm, and Action objects, the Struts controller layer provides several other specialized components, including Action- Mappings and the ActionServlet. Struts also supports localizing your application from the controller layer.
4.4 ActionMappings
In a web application, every resource must be referred to through a Uniform Resource Identifier (URI). This includes HTML pages, JSP pages, and any custom actions. To give the custom Actions a URI, or path, the Struts framework provides an ActionMapping object. Like the ActionForwards and ActionForms, the Actionmapping usually defined in the XML configuration file. This also allows the same Action object to be used by different mappings. For example, one mapping may require validation; another may not.
4.5 ActionServlet
The Struts ActionServlet works quietly behind the scenes, binding the other components together. Although it can be subclassed, most Struts 1.0 developers treat the ActionServlet as a blackbox: they configure it and leave it alone
4.6 Localization
Web applications also interact with users through prompts and messages. The Struts components have localization features built in so that applications can be written for an international audience.
Thanks
JavaServer Pages is a Java technology that allows developers to dynamically generate HTML, XML or other types of web pages....
» complete changeJavaServer Pages is a Java technology that allows developers to dynamically generate HTML, XML or other types of web pages. JSPs are compiled into [[servlets]]. Both JSPs and servlets are specified as part of the Java Community Process and the Java Enterprise Edition [[J2EE]] efforts. efforts..
h1. "JSP Questions":http://www.developersbook.com/jsp/interview-questions/jsp-interview-questions-faqs.php.
JavaServer Pages is a Java technology that allows developers to dynamically generate HTML, XML or other types of web pages....
» complete changeJavaServer Pages is a Java technology that allows developers to dynamically generate HTML, XML or other types of web pages. JSPs are compiled into [[servlets]]. Both JSPs and servlets are specified as part of the Java Community Process and the Java Enterprise Edition [[J2EE]] efforts.. efforts.
"JSP Questions":http://www.developersbook.com/jsp/interview-questions/jsp-interview-questions-faqs.php.
JavaServer Pages is a Java technology that allows developers to dynamically generate HTML, XML or other types of web pages. JSPs are compiled into [[servlets]]. Both JSPs and servlets are specified as part of the Java Community Process and the Java Enterprise Edition [[J2EE]] efforts.
"JSP Questions":http://www.developersbook.com/jsp/interview-questions/jsp-interview-questions-faqs.php.
"JSP Questions":http://www.developersbook.com/jsp/interview-questions/jsp-interview-questions-faqs.php.
» complete changeJavaServer Pages is a Java technology that allows developers to dynamically generate HTML, XML or other types of web pages. JSPs are compiled into [[servlets]]. Both JSPs and servlets are specified as part of the Java Community Process and the Java Enterprise Edition [[J2EE]] efforts.
"JSP Questions":http://www.developersbook.com/jsp/interview-questions/jsp-interview-questions-faqs.php.
"Web Application Development with Java Server Pages (JSP)":http://blog.eukhost.com/2006/06/08/web-application-development-using-java-server-pages-jsp...
JavaServer Pages is a Java technology that allows developers to dynamically generate HTML, XML or other types of web pages. JSPs are compiled into [[servlets]]. Both JSPs and servlets are specified as part of the Java Community Process and the Java Enterprise Edition [[J2EE]] efforts.
"Web Application Development with Java Server Pages (JSP)":http://blog.eukhost.com/2006/06/08/web-application-development-using-java-server-pages-jsp
"Web Application Development with Java Server Pages (JSP)":http://blog.eukhost.com/2006/06/08/web-application-development-using-java-server-pages-jsp...
» complete changeJavaServer Pages is a Java technology that allows developers to dynamically generate HTML, XML or other types of web pages. JSPs are compiled into [[servlets]]. Both JSPs and servlets are specified as part of the Java Community Process and the Java Enterprise Edition [[J2EE]] efforts.
"Web Application Development with Java Server Pages (JSP)":http://blog.eukhost.com/2006/06/08/web-application-development-using-java-server-pages-jsp
1 What are application frameworks?
_ They are known to work well in other applications.
_ They can also be used by other teams...
» complete changeStruts is hosted by the Apache Software Foundation (ASF) as part of its Jakarta project. The framework is called āStrutsā to remind us of the invisible underpinnings that hold up our houses, buildings, bridges, and, indeed, ourselves when we are on stilts. This is an excellent description of the role Struts plays in developing web applications. When raising physical structures, construction engineers use struts to provide support for each floor of a building. Likewise, software engineers use Struts to support each layer of a business application.
1 What are application frameworks?
A framework is a reusable, semi-complete application that can be specialized to produce custom applications . Like people, software applications are more alike than they are different. They run on the reresame computers, expect input from the same devices, output to the same displays, and save data to the same hard disks. Developers working on conventional desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Application frameworks build on this common ground to provide developers with a reusable structure that can serve as the foundation for their own products. A framework provides developers with a set of backbone components that have the following characteristics:
_ They are known to work well in other applications.
_ They are ready to use with the next project.
_ They can also be used by other teams in the organization.
Frameworks are the classic build-versus-buy proposition. If you build it, you will understand it when you are doneābut how long will it be before you can roll your own? If you buy it, you will have to climb the learning curveāand how long is that going to take? There is no right answer here, but most observers would agree that frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially for larger projects.
2. Enabling technologies
Applications developed with Struts are based on a number of enabling technologies. These components are not specific to Struts and underlie every Java web application. A reason that developers use frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP.
2.1 Java servlets
Sunās Java Servlet platform directly addresses the two main drawbacks of CGI programs.
First, servlets offer better performance and utilization of resources than conventional CGI programs. Second, the write-once, run-anywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM). A servlet looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications. The servlet itself is simply a Java class that has been compiled into byte code, like any other Java object. The servlet has access to a rich API of HTTP-specific services, but it is still just another Java object running in an application and can leverage all your other Java assets. To give conventional web servers access to servlets, the servlets are plugged into containers. The servlet container is attached to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes the servlet. But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs.Once the servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init() method to hold references to expensive resources, such as database connections or EJB Home Interfaces,so that they can be shared between requests. Acquiring resources like these can take several secondsāwhich is longer than many surfers are willing to wait. The other edge of the sword is that, since servlets are multithreaded, servlet developers must take special care to be sure their servlets are thread-safe. To learn more about servlet programming, we recommend Java Servlets by Example, by AlanR. Williamson. The definitive source for Servlet information is the Java Servlet Specification.
2.2 JavaServer Pages
While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developers are still stuck with using println statements to render the HTML.That is all too common in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more complex, Java developers end up being cast into the role of HTML page designers. Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, making it difficult for team members to specialize.To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a single component. To build Java-Server Pages, developers start by creating HTML pages in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page. Scripting elements are tags that encapsulate logic that is recognized by the JSP. You can easily pick out scripting elements on JSP pages by looking for code that begins with <% and ends with %>. There are three different types of scripting elements: expressions, scriptlets, and DeclarationsćTo be seen as a JSP page, the file just needs to be saved with an extension of .jsp. When a client requests the JSP page, the container translates the page into a source code file for a Java servlet and compiles the source into a Java class fileā just as you would do if you were writing a servlet from scratch. At runtime, the container can also check the last modified date of the JSP file against the class file. If the JSP file has changed since it was last compiled, the container will retranslate and rebuild the page all over again. Project managers can now assign the presentation layer to HTML developers, who then pass on their work to Java developers to complete the business-logic portion. The important thing to remember is that a JSP page is really just a servlet. Anything you can do with a servlet, you can do with a JSP.
2.3 JavaBeans
JavaBeans are Java classes which conform to a set of design patterns that make them easier to use with development tools and other components. DEFINITION A JavaBean is a reusable software component written in Java. To qualify as a JavaBean, the class must be concrete and public, and have a noargument constructor. JavaBeans expose internal fields as properties by providing public methods that follow a consistent design pattern. Knowing that the property names follow this pattern, other Java classes are able to use introspection to discover and manipulate JavaBean properties.The JavaBean design patterns provide access to the beanās internal state through two flavors of methods: accessors are used to read a JavaBeanās state; mutators are used to change a JavaBeanās state. Mutators are always prefixed with lowercase token set followed by the property name. The first character in the property name must be uppercase. The return value is always voidāmutators only change property values; they do not retrieve them. The mutator for a simple property takes only one parameter in its signature, which can be of any type. Mutators are often nicknamed setters after their prefix. A similar design pattern is used to create the accessor method signature. Accessor methods are always prefixed with the lowercase token get, followed by the property name. The first character in the property name must be uppercase. The return value will match the method parameter in the corresponding mutator.Accessors for simple properties cannot accept parameters in their method signature. Not surprisingly, accessors are often called getters. If the accessor returns a logical value, there is a variant pattern. Instead of using the lowercase token get, a logical property can use the prefix is, followed by the property name. The first character in the property name must be uppercase. The return value will always be a logical valueāeither boolean or Boolean. Logical accessors cannot accept parameters in their method signature. The canonical method signatures play an important role when working with Java-Beans. Other components are able to use the Java Reflection API to discover a JavaBeanās properties by looking for methods prefixed by set, is, or get. If a component finds such a signature on a JavaBean, it knows that the method can be used to access or change the beanās properties. Sun introduced JavaBeans to work with GUI components, but they are now used with every aspect of Java development, including web applications. When Sun engineers developed the JSP tag extension classes, they designed them to work with JavaBeans. The dynamic data for a page can be passed as a JavaBean, and the JSP tag can then use the beanās properties to customize the output.
3 Model 2
The 0.92 release of the Servlet/JSP Specification described Model 2 as an architecture that uses servlets and JSP pages together in the same application. The term Model 2 disappeared from later releases, but it remains in popular use among Java web developers. Under Model 2, servlets handle the data access and navigational flow, while JSP pages handle the presentation. Model 2 lets Java engineers and HTML developers each work on their own part of the application. A change in one part of a Model 2 application does not mandate a change to another part of the application. HTML developers can often change the look and feel of an application without changing how the back-office servlets work. The Struts framework is based on the Model 2 architecture. It provides a controller servlet to handle the navigational flow and special classes to help with the data access. A substantial custom tag library is bundled with the framework to make Struts easy to use with JSP pages.
4 Struts controller components
The Struts controller is a set of programmable components that allow developers to define exactly how their application interacts with the user. These components hide nasty, cumbersome implementation details behind logical names. Developers can program these details once, then go back to thinking in terms of what the program does rather than how it does it. Users interact with a web application through hyperlinks and HTML forms. The hyperlinks lead to pages that display data and other elements, such as text and images.
4.1 Hyperlinks
To the application developer, a hyperlink is a path to some resource in the application. This may be a web page or a custom action. It may also include special parameters. In Struts, these objects have a logical name and a path property. This lets developers set the path and then refer to the ActionForward by name. ActionForwards are usually defined in an XML configuration file that Struts reads when the web application loads. Struts uses the XML definitions to create the Struts configuration, which includes a list of ActionForwards.
4.2 HTML forms
The web protocols, HTTP and HTML, provide a mechanism for submitting data from a form but leave receiving the data as an exercise for the developer. The Struts framework provides an ActionForm class, which is designed to handle input from an HTML form, validate the input, and redisplay the form to the user for correction (when needed), along with any corresponding prompts or messages. ActionForms are just JavaBeans with a couple of standard methods to manage the validation and revision cycle.Struts utomatically matches the JavaBean properties with the attributes of the HTML controls. The developer defines the Action-Form class. Struts does the rest.This class will automatically populate the username field from a form with an HTML form element of the same name.
4.3 Custom actions
An HTML form uses an action parameter to tell the browser where to send the formās data. The Struts framework supplies a corresponding Action class to receive such data. The framework automatically creates, populates, validates, and finally passes the appropriate ActionForm to the Action object. The Action can then get the data it needs directly from the ActionForm bean. An Action concludes by returning an ActionForward object to the controller. This allows the Action to choose a definition using logical names, like continue or cancel, rather than system paths. To ensure extensibility, the controller also passes the current request and response object. In practice, an Action can do anything a Java Servlet can do. In addition to the ActionForward, ActionForm, and Action objects, the Struts controller layer provides several other specialized components, including Action- Mappings and the ActionServlet. Struts also supports localizing your application from the controller layer.
4.4 ActionMappings
In a web application, every resource must be referred to through a Uniform Resource Identifier (URI). This includes HTML pages, JSP pages, and any custom actions. To give the custom Actions a URI, or path, the Struts framework provides an ActionMapping object. Like the ActionForwards and ActionForms, the Actionmapping usually defined in the XML configuration file. This also allows the same Action object to be used by different mappings. For example, one mapping may require validation; another may not.
4.5 ActionServlet
The Struts ActionServlet works quietly behind the scenes, binding the other components together. Although it can be subclassed, most Struts 1.0 developers treat the ActionServlet as a blackbox: they configure it and leave it alone
4.6 Localization
Web applications also interact with users through prompts and messages. The Struts components have localization features built in so that applications can be written for an international audience.
Opopoppop
Thanks
Opopoppop
Thanks
» complete changeStruts is hosted by the Apache Software Foundation (ASF) as part of its Jakarta project. The framework is called āStrutsā to remind us of the invisible underpinnings that hold up our houses, buildings, bridges, and, indeed, ourselves when we are on stilts. This is an excellent description of the role Struts plays in developing web applications. When raising physical structures, construction engineers use struts to provide support for each floor of a building. Likewise, software engineers use Struts to support each layer of a business application.
1 What are application frameworks?
A framework is a reusable, semi-complete application that can be specialized to produce custom applications . Like people, software applications are more alike than they are different. They run on the reresame computers, expect input from the same devices, output to the same displays, and save data to the same hard disks. Developers working on conventional desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Application frameworks build on this common ground to provide developers with a reusable structure that can serve as the foundation for their own products. A framework provides developers with a set of backbone components that have the following characteristics:
_ They are known to work well in other applications.
_ They are ready to use with the next project.
_ They can also be used by other teams in the organization.
Frameworks are the classic build-versus-buy proposition. If you build it, you will understand it when you are doneābut how long will it be before you can roll your own? If you buy it, you will have to climb the learning curveāand how long is that going to take? There is no right answer here, but most observers would agree that frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially for larger projects.
2. Enabling technologies
Applications developed with Struts are based on a number of enabling technologies. These components are not specific to Struts and underlie every Java web application. A reason that developers use frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP.
2.1 Java servlets
Sunās Java Servlet platform directly addresses the two main drawbacks of CGI programs.
First, servlets offer better performance and utilization of resources than conventional CGI programs. Second, the write-once, run-anywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM). A servlet looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications. The servlet itself is simply a Java class that has been compiled into byte code, like any other Java object. The servlet has access to a rich API of HTTP-specific services, but it is still just another Java object running in an application and can leverage all your other Java assets. To give conventional web servers access to servlets, the servlets are plugged into containers. The servlet container is attached to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes the servlet. But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs.Once the servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init() method to hold references to expensive resources, such as database connections or EJB Home Interfaces,so that they can be shared between requests. Acquiring resources like these can take several secondsāwhich is longer than many surfers are willing to wait. The other edge of the sword is that, since servlets are multithreaded, servlet developers must take special care to be sure their servlets are thread-safe. To learn more about servlet programming, we recommend Java Servlets by Example, by AlanR. Williamson. The definitive source for Servlet information is the Java Servlet Specification.
2.2 JavaServer Pages
While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developers are still stuck with using println statements to render the HTML.That is all too common in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more complex, Java developers end up being cast into the role of HTML page designers. Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, making it difficult for team members to specialize.To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a single component. To build Java-Server Pages, developers start by creating HTML pages in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page. Scripting elements are tags that encapsulate logic that is recognized by the JSP. You can easily pick out scripting elements on JSP pages by looking for code that begins with <% and ends with %>. There are three different types of scripting elements: expressions, scriptlets, and DeclarationsćTo be seen as a JSP page, the file just needs to be saved with an extension of .jsp. When a client requests the JSP page, the container translates the page into a source code file for a Java servlet and compiles the source into a Java class fileā just as you would do if you were writing a servlet from scratch. At runtime, the container can also check the last modified date of the JSP file against the class file. If the JSP file has changed since it was last compiled, the container will retranslate and rebuild the page all over again. Project managers can now assign the presentation layer to HTML developers, who then pass on their work to Java developers to complete the business-logic portion. The important thing to remember is that a JSP page is really just a servlet. Anything you can do with a servlet, you can do with a JSP.
2.3 JavaBeans
JavaBeans are Java classes which conform to a set of design patterns that make them easier to use with development tools and other components. DEFINITION A JavaBean is a reusable software component written in Java. To qualify as a JavaBean, the class must be concrete and public, and have a noargument constructor. JavaBeans expose internal fields as properties by providing public methods that follow a consistent design pattern. Knowing that the property names follow this pattern, other Java classes are able to use introspection to discover and manipulate JavaBean properties.The JavaBean design patterns provide access to the beanās internal state through two flavors of methods: accessors are used to read a JavaBeanās state; mutators are used to change a JavaBeanās state. Mutators are always prefixed with lowercase token set followed by the property name. The first character in the property name must be uppercase. The return value is always voidāmutators only change property values; they do not retrieve them. The mutator for a simple property takes only one parameter in its signature, which can be of any type. Mutators are often nicknamed setters after their prefix. A similar design pattern is used to create the accessor method signature. Accessor methods are always prefixed with the lowercase token get, followed by the property name. The first character in the property name must be uppercase. The return value will match the method parameter in the corresponding mutator.Accessors for simple properties cannot accept parameters in their method signature. Not surprisingly, accessors are often called getters. If the accessor returns a logical value, there is a variant pattern. Instead of using the lowercase token get, a logical property can use the prefix is, followed by the property name. The first character in the property name must be uppercase. The return value will always be a logical valueāeither boolean or Boolean. Logical accessors cannot accept parameters in their method signature. The canonical method signatures play an important role when working with Java-Beans. Other components are able to use the Java Reflection API to discover a JavaBeanās properties by looking for methods prefixed by set, is, or get. If a component finds such a signature on a JavaBean, it knows that the method can be used to access or change the beanās properties. Sun introduced JavaBeans to work with GUI components, but they are now used with every aspect of Java development, including web applications. When Sun engineers developed the JSP tag extension classes, they designed them to work with JavaBeans. The dynamic data for a page can be passed as a JavaBean, and the JSP tag can then use the beanās properties to customize the output.
3 Model 2
The 0.92 release of the Servlet/JSP Specification described Model 2 as an architecture that uses servlets and JSP pages together in the same application. The term Model 2 disappeared from later releases, but it remains in popular use among Java web developers. Under Model 2, servlets handle the data access and navigational flow, while JSP pages handle the presentation. Model 2 lets Java engineers and HTML developers each work on their own part of the application. A change in one part of a Model 2 application does not mandate a change to another part of the application. HTML developers can often change the look and feel of an application without changing how the back-office servlets work. The Struts framework is based on the Model 2 architecture. It provides a controller servlet to handle the navigational flow and special classes to help with the data access. A substantial custom tag library is bundled with the framework to make Struts easy to use with JSP pages.
4 Struts controller components
The Struts controller is a set of programmable components that allow developers to define exactly how their application interacts with the user. These components hide nasty, cumbersome implementation details behind logical names. Developers can program these details once, then go back to thinking in terms of what the program does rather than how it does it. Users interact with a web application through hyperlinks and HTML forms. The hyperlinks lead to pages that display data and other elements, such as text and images.
4.1 Hyperlinks
To the application developer, a hyperlink is a path to some resource in the application. This may be a web page or a custom action. It may also include special parameters. In Struts, these objects have a logical name and a path property. This lets developers set the path and then refer to the ActionForward by name. ActionForwards are usually defined in an XML configuration file that Struts reads when the web application loads. Struts uses the XML definitions to create the Struts configuration, which includes a list of ActionForwards.
4.2 HTML forms
The web protocols, HTTP and HTML, provide a mechanism for submitting data from a form but leave receiving the data as an exercise for the developer. The Struts framework provides an ActionForm class, which is designed to handle input from an HTML form, validate the input, and redisplay the form to the user for correction (when needed), along with any corresponding prompts or messages. ActionForms are just JavaBeans with a couple of standard methods to manage the validation and revision cycle.Struts utomatically matches the JavaBean properties with the attributes of the HTML controls. The developer defines the Action-Form class. Struts does the rest.This class will automatically populate the username field from a form with an HTML form element of the same name.
4.3 Custom actions
An HTML form uses an action parameter to tell the browser where to send the formās data. The Struts framework supplies a corresponding Action class to receive such data. The framework automatically creates, populates, validates, and finally passes the appropriate ActionForm to the Action object. The Action can then get the data it needs directly from the ActionForm bean. An Action concludes by returning an ActionForward object to the controller. This allows the Action to choose a definition using logical names, like continue or cancel, rather than system paths. To ensure extensibility, the controller also passes the current request and response object. In practice, an Action can do anything a Java Servlet can do. In addition to the ActionForward, ActionForm, and Action objects, the Struts controller layer provides several other specialized components, including Action- Mappings and the ActionServlet. Struts also supports localizing your application from the controller layer.
4.4 ActionMappings
In a web application, every resource must be referred to through a Uniform Resource Identifier (URI). This includes HTML pages, JSP pages, and any custom actions. To give the custom Actions a URI, or path, the Struts framework provides an ActionMapping object. Like the ActionForwards and ActionForms, the Actionmapping usually defined in the XML configuration file. This also allows the same Action object to be used by different mappings. For example, one mapping may require validation; another may not.
4.5 ActionServlet
The Struts ActionServlet works quietly behind the scenes, binding the other components together. Although it can be subclassed, most Struts 1.0 developers treat the ActionServlet as a blackbox: they configure it and leave it alone
4.6 Localization
Web applications also interact with users through prompts and messages. The Struts components have localization features built in so that applications can be written for an international audience.
Opopoppop
Thanks
Thanks
» complete changeStruts is hosted by the Apache Software Foundation (ASF) as part of its Jakarta project. The framework is called āStrutsā to remind us of the invisible underpinnings that hold up our houses, buildings, bridges, and, indeed, ourselves when we are on stilts. This is an excellent description of the role Struts plays in developing web applications. When raising physical structures, construction engineers use struts to provide support for each floor of a building. Likewise, software engineers use Struts to support each layer of a business application.
1 What are application frameworks?
A framework is a reusable, semi-complete application that can be specialized to produce custom applications . Like people, software applications are more alike than they are different. They run on the reresame computers, expect input from the same devices, output to the same displays, and save data to the same hard disks. Developers working on conventional desktop applications are accustomed to toolkits and development environments that leverage the sameness between applications. Application frameworks build on this common ground to provide developers with a reusable structure that can serve as the foundation for their own products. A framework provides developers with a set of backbone components that have the following characteristics:
_ They are known to work well in other applications.
_ They are ready to use with the next project.
_ They can also be used by other teams in the organization.
Frameworks are the classic build-versus-buy proposition. If you build it, you will understand it when you are doneābut how long will it be before you can roll your own? If you buy it, you will have to climb the learning curveāand how long is that going to take? There is no right answer here, but most observers would agree that frameworks such as Struts provide a significant return on investment compared to starting from scratch, especially for larger projects.
2. Enabling technologies
Applications developed with Struts are based on a number of enabling technologies. These components are not specific to Struts and underlie every Java web application. A reason that developers use frameworks like Struts is to hide the nasty details behind acronyms like HTTP, CGI, and JSP.
2.1 Java servlets
Sunās Java Servlet platform directly addresses the two main drawbacks of CGI programs.
First, servlets offer better performance and utilization of resources than conventional CGI programs. Second, the write-once, run-anywhere nature of Java means that servlets are portable between operating systems that have a Java Virtual Machine (JVM). A servlet looks and feels like a miniature web server. It receives a request and renders a response. But, unlike conventional web servers, the servlet application programming interface (API) is specifically designed to help Java developers create dynamic applications. The servlet itself is simply a Java class that has been compiled into byte code, like any other Java object. The servlet has access to a rich API of HTTP-specific services, but it is still just another Java object running in an application and can leverage all your other Java assets. To give conventional web servers access to servlets, the servlets are plugged into containers. The servlet container is attached to the web server. Each servlet can declare what URL patterns it would like to handle. When a request matching a registered pattern arrives, the web server passes the request to the container, and the container invokes the servlet. But unlike CGI programs, a new servlet is not created for each request. Once the container instantiates the servlet, it will just create a new thread for each request. Java threads are much less expensive than the server processes used by CGI programs.Once the servlet has been created, using it for additional requests incurs very little overhead. Servlet developers can use the init() method to hold references to expensive resources, such as database connections or EJB Home Interfaces,so that they can be shared between requests. Acquiring resources like these can take several secondsāwhich is longer than many surfers are willing to wait. The other edge of the sword is that, since servlets are multithreaded, servlet developers must take special care to be sure their servlets are thread-safe. To learn more about servlet programming, we recommend Java Servlets by Example, by AlanR. Williamson. The definitive source for Servlet information is the Java Servlet Specification.
2.2 JavaServer Pages
While Java servlets are a big step up from CGI programs, they are not a panacea. To generate the response, developers are still stuck with using println statements to render the HTML.That is all too common in servlets that generate the HTTP response. There are libraries that can help you generate HTML, but as applications grow more complex, Java developers end up being cast into the role of HTML page designers. Meanwhile, given the choice, most project managers prefer to divide development teams into specialized groups. They like HTML designers to be working on the presentation while Java engineers sweat the business logic. Using servlets alone encourages mixing markup with business logic, making it difficult for team members to specialize.To solve this problem, Sun turned to the idea of using server pages to combine scripting and templating technologies into a single component. To build Java-Server Pages, developers start by creating HTML pages in the same old way, using the same old HTML syntax. To bring dynamic content into the page, the developer can also place JSP scripting elements on the page. Scripting elements are tags that encapsulate logic that is recognized by the JSP. You can easily pick out scripting elements on JSP pages by looking for code that begins with <% and ends with %>. There are three different types of scripting elements: expressions, scriptlets, and DeclarationsćTo be seen as a JSP page, the file just needs to be saved with an extension of .jsp. When a client requests the JSP page, the container translates the page into a source code file for a Java servlet and compiles the source into a Java class fileā just as you would do if you were writing a servlet from scratch. At runtime, the container can also check the last modified date of the JSP file against the class file. If the JSP file has changed since it was last compiled, the container will retranslate and rebu
