Using Java Beans Technology for Java Web Applications – Develop Java Web Applications to Access Databases

8.1.5   Using Java Beans Technology for Java Web Applications

In recent years, the Java beans technique has been widely applied in Java Web applications. In fact, a Java bean can be considered an extended Java help class, as we discussed in the previous sections, and the main purpose of a Java bean is to handle JDBC- and database-related operations as well as business logic in a Web application.

In fact, Java beans are reusable components, and the main purpose of using Java beans is to separate business logic from presentation.

That is, a Java bean is just an instance of a class.

Once a JavaBean is created and loaded, it can be used by all parts of your application based on its scope. The so-called scope defines the section of your application that can access and use this bean. Generally, there are four popular scopes available to a Java Bean object. The default scope is page scope.

  • page scope: The bean is accessible within a JSP page with the <jsp: useBean> tag or any of the page’s static include files until the page sends a response to the client or forwards a request to another page. In other words, as long as the process is on the current page, the bean can be accessed and used until the process is transferred to other pages.
  • request scope: The bean is accessible from any JSP page as long as the same request is processed in that page until a JSP page sends a response to the client or forwards the request to another page. In other words, the bean can be used until a different request has been forwarded or a response for that request has been received, which means that the lifetime or scope of that request has been completed.
  • session scope: The bean is accessible from any JSP page in the same session as the JSP page that creates the bean. A session can be considered a common place where many JSP pages can exist and share. The JSP page in which you create the Java bean must have a JSP page directive <%@ page %> with the session = true.
  • application scope: The bean can be accessed from any JSP page in the same application as the JSP page that creates the bean. In other words, any JSP page can use the bean as long as that page is included in the application in which the JSP page that creates the bean is included.

Leave a Comment



                    Blog, Contribute ,Privacy,Terms of Use,Trademarks,© estherknow 2024