Basic Bean Use in JSP
Format
- <jsp:useBean id="name" class="package.Class" />
Purpose
- Allow instantiation of Java classes without explicit Java programming (XML-compatible syntax)
Notes
- Simple interpretation: JSP action<jsp:useBean id="book1" class=”myBeans.Book" />can be thought of as equivalent to the scriptlet<% myBeans.Book book1 = new myBeans.Book(); %>
- But useBean has two additional advantages:
- It is easier to derive object values from request parameters
- It is easier to share objects among pages or servlets