JavaBeans

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% [?]

You can leave a response, or trackback from your own site.

Leave a Reply

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars