Show TOC

Procedure documentationUsing Scriptlets Locate this document in the navigation structure

 

You can use JSP scriptlets to embed Java code in the HTML content of your JSP page. You can use them for different purposes, such as to perform iterations in cycles, access Java objects and call methods on those objects, and so on. You can also easily embed expression elements in scriptlets.

Accessing an Enterprise Bean in a Scriptlet

If your application uses enterprise beans to deal with data persistency, you can access them and call their methods in a scriptlet.

Accessing an Enterprise Bean in a Scriptlet

If your application uses enterprise beans to deal with data persistency, you can access them and call their methods in a scriptlet.

Example Example

For example, you put the LocationModel bean in a scriptlet, and call methods on it to determine the location where the customer wants to rent a car from.

Here is the scriptlet code:

  1. <%
      LocationModel pickupLocation = (LocationModel)session.getAttribute(Constants.PICKUP_LOCATION);
      String[] countries = (String[])session.getAttribute(Constants.COUNTRIES);
      String country = pickupLocation.getCountry();
      String[] cities = (String[])session.getAttribute(Constants.CITIES);
      String city = pickupLocation.getCity();
      String selectedCountry = "";
      String selectedCity = "";
      String location = pickupLocation.getLocationId().toString();
      String selectedLocation = "";
      Collection locations = (Collection)session.getAttribute(Constants.LOCATIONS);
    %>
    
End of the code.