Requirements for JavaBeans:
- there have to be set/get methods specified
- has to have public default constructor (without parameters)
- it should be in a package
- serializable
- get/set methods has to have the same data type!
- bean cannot modify content of a page!
… in general, JavaBean is a standard Class.
It can be used as a simple component in a JSP page.
- get method has to be fast, and it should be plain and simple.
usage in a JSP page:
<jsp:useBean id=”nameOfBean” scope=”session” class=”myPackage.Counter”>
<jsp:setProperty name=”nameOfBean” property=”myCount”>
this is the same as
<%= Counter.myCount %>
with JSTL Expression language:
<c:out value=”${Counter.myCount}”>
automatically set the bean attributes from names (!important!):
<jsp:setProperty name=”pocetMiest” property=”*”>
Scope can be:
- application - the bean is available in all application, when that’s in more JSP pages, one of them can create it once and other JSP pages can use it. It’s something like a global object for all application.
- session - stored data, just for this session
- request - just for request or forward
- page - smallest scope, just on a page that is called (forwarded or included)
Popularity: 1% [?]

February 1st, 2009
admin
Posted in 
