Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Short answer: JSP 2.0 does not offer scriptless Expression Language (EL) syntax for calling an arbitrary public, nonstatic JavaBean method. Its bean actions and EL property expressions read or set properties. For scriptless pages, use an EL function for a public static helper or a custom tag to expose instance behavior; if scripting is permitted, a scriptlet or JSP expression can call the method directly.

What JSP 2.0 bean syntax can do

<jsp:useBean> locates an existing bean or creates one, then makes it available under an identifier. You can use that identifier with the standard property actions or EL property syntax.

<jsp:useBean id="customer" class="example.Customer" scope="request" />
<jsp:getProperty name="customer" property="name" />

<!-- With EL enabled: reads the name property -->
${customer.name}

<jsp:getProperty> writes a bean property’s value to the response, converted to a string. <jsp:setProperty> assigns a property. These actions use JavaBeans property accessors; they do not turn an arbitrary method name into a callable operation. EL syntax such as ${customer.name} likewise reads a property, rather than invoking a public nonstatic method. The JSP 2.0 specification describes the property-based behavior of these actions.

Choose a route based on the method and scripting requirement

Need JSP 2.0 approach Constraint
Read or write a bean property <jsp:getProperty>, <jsp:setProperty>, or EL property access Works with properties, not arbitrary operations.
Call a static helper from a scriptless page Declare an EL function in a tag library descriptor (TLD), then call it with function syntax The mapped Java method must be public and static.
Expose instance behavior to a scriptless page Implement or use a custom tag Requires a tag interface and implementation that expose the behavior.
Call a method directly where scripting is allowed Use a scriptlet or JSP expression with the bean reference Java code is mixed into the JSP markup.

Call a static helper with an EL function

JSP 2.0 EL functions provide scriptless calls to public static Java methods. Declare the function and its Java method in a TLD, then use the declared function name in the page. This is appropriate when the operation can be represented as a static utility; it does not provide a general call to an instance method on a bean.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The InfoWorld discussion of calling bean methods in JSP 2.0 describes this distinction and the custom-tag alternative.

Expose instance behavior with a custom tag

If the page must remain scriptless and the behavior belongs to a particular bean instance, a custom tag can provide a page-level interface to that behavior. The tag implementation can receive the bean or the required inputs and perform the operation. This is more setup than property access, but it avoids pretending that JSP 2.0 EL supports arbitrary instance-method syntax.

Use a scriptlet only when scripting is acceptable

When a legacy page allows scripting, Java invocation syntax can call the method through the bean reference. For example, a JSP scriptlet could call customer.refresh(). Oracle’s JSP FAQ confirms that JSP pages can include Java scriptlets and describes JSP processing and bean actions.

A scriptlet is a direct option, not a scriptless one: it mixes Java code with presentation markup. Where the application design permits, keep business or request-processing work outside the view and pass the JSP the values it needs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose bean scope deliberately

The Java EE 5 tutorial lists four scopes for <jsp:useBean>:

  • page: available on the current page.
  • request: available for the current request.
  • session: available with the user’s session.
  • application: shared across the application.

Do not put mutable per-user state in application scope: that scope is shared, rather than isolated to one user’s session.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Do not apply later Jakarta EL features to JSP 2.0

The Jakarta Server Pages 3.0 specification documents a later version and includes later EL facilities, such as deferred method expressions. It is not evidence that JSP 2.0 supports arbitrary nonstatic JavaBean calls through EL. For JSP 2.0, distinguish property access from method invocation and select a static EL function, custom tag, or scriptlet according to the page’s constraints.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.