Why should I use the <jsp:useBean> tag, instead of just instantiating beans directly inside scriptlets?
Created May 4, 2012
Alex Chaffee
The arguments in favor of using the useBean tag are:
- The tag syntax is arguably less intimidating to HTML designers.
- useBean has a "scope" parameter that automatically determines whether the bean should be stored as a local variable, a request variable, a session variable, or an application attribute. If you were to create beans explicitly you'd have to do it 4 different ways for the 4 different scopes.
- If the variable is persistent (session or application), useBean initializes it if necessary, but fetches the variable if it already exists.
- The tags are potentially more portable to future versions of the JSP spec, or alternate implementations (for example, a hypothetical JSP engine that stores variables in a database, or shares them across server processes).
The above is excerpted from my article at JavaWorld, Using XML and JSP together (March 2000).