Entering content frame

Procedure documentation Using Scriptlets Locate the document in its SAP Library structure

Use

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. For example, the step1.jsp of the car rental application puts the LocationModel entity bean in a scriptlet, and calls methods on it that are related to determining the location where the customer wants to rent a car from. Here is the scriptlet code:

This graphic is explained in the accompanying text

<%

  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);

%>

 

 

Leaving content frame