By: Emiley J Printer Friendly Format
It is necessary to know when to use tags as opposed to JavaBeans for wrapping up reusable functionality. After all, JavaBeans are reusable components and the JSP specification provides a built-in mechanism for integrating and utilizing the features provided by JavaBeans. Although both technologies can be used to achieve the same goal, that of encapsulating and abstracting data away from the JSP page, there are significant differences between the two.
JavaBeans are good general-purpose objects that encapsulate state in a portable “bucket.” We will continue to use these in our examples because they make great business objects. Tags are a web-specific technology. Tags are primarily for generating presentation elements, and as such they primarily encapsulate behavior. In addition, custom tags are aware of the environment in which they are running. For example, custom tags have access to the same implicit objects as the ones available when developing JSP pages: pageContext, request, response, session, and so on. JavaBeans, however, are components that can be reused within any Java environment; hence, they don’t know about such JSP specifics. Therefore, custom tags are a much better choice for encapsulating reusable functionality that will be used on JSP pages. Keep in mind the following rules:
- Use JavaBeans for representing and storing information and state. An example is building JavaBeans to represent the business objects in your application.
- Use custom tags to represent and implement actions that occur on those JavaBeans, as well as logic related to the presentation of information. An example from JSTL is iterating over a collection of objects or conditional logic.
Comment on this tutorial
- Data Science
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews
Subscribe to Tutorials
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
1. very nice article....if you want more details abou
View Tutorial By: Anil Nivargi at 2015-01-22 19:27:21