Developing with SAP NetWeaver Developer Studio  |  Developing MI Applications  |  Example 1 JSP   |  Example 3 JSP   |  Example 1 AWT

 

Getting Started - Example 2 JSP

Using and evaluating events in JSP

The 2nd example program extends the first by adding an initial JSP with an input field. The user input is read and displayed together with the configuration information in a second JSP. Technically, the program is realized as a servlet with event handling, two JSP and a bean.
Being an extension of the first example, program demonstrates how to handle events, read data from an input fields in JSP and call another JSP when the event is processed.

To download the example program, click here

Components

The example uses following packages:

import com.sap.ip.me.api.conf.Configuration;
import com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet;
import com.sap.ip.me.api.services.Log;

The following classes and JSP are implemented and contained in the application archive, that can be downloaded from above.

Java

Description
SystemInfo.java Implementation of the servlet.
Constants.java Interface defining all text strings used in SystemInfo.java.
BasicDataHandler Generates the data to be displayed.
TableViewBean.java Implementation of the bean that is loaded by the servlet and read by the JSP.

JSP

Description
welcome.jsp Initial JSP displaying an input field and a submit button.
tableView.jsp JSP to display the information.

Implemented Classes in the Servlet for the Example

We create a class SystemInfo that extends the class AbstractMEHttpServlet and implements Constants. Constants is an interface in which we define all relevant variables for the application. All variables used in Constants are written in uppercase characters. So anytime you see an uppercase variable used in class SystemInfo you will find the definition in interface Constants.

The class SystemInfo extends AbstractMEHttpServlet which extends javax.servlet.http.HttpServlet itself. The method doHandleEvent does:

If an EVENT_NAME event occurred, the TABLEVIEW_JSP is called and the data is displayed on your web browser. In all other cases INITIAL_JSP is called and asks you for your name.

BasicDataHandler

This class generates the data that is displayed by the JSP. The class provides get methods to access the data. In this example it generated data by accessing the MI configuration API. It creates an instance of the Configuration class and uses the methods getOperatingSystemName(), getJVMVendorName() and getMERuntime() to fill the array of the bean. It uses the method stringLoad to fill a standard text into the cell when no variable is available.

Bean

The bean serves as data bag. It has a string, a string array and two variables that define the length and width of the string array. All variables have get and set methods.

JSP

welcome.jsp
Displays a welcome message and allows to enter a user name. The JSP contains a "Submit" button to send the page.

An interesting JSP related phenomenon:
When there is only one input field in a form, the "submit" button event is NOT activated when you want to submit the form by simply pressing the "enter" key (on the keyboard). You have to click on the "Submit" button with the mouse.
You could extend this JSP with an additional input field (also HIDDEN), that the keyboard input works.



tableView.jsp
The JSP gets the bean from the session context with the useBean command. It displays the the title and then uses the HTML grid (<td>, <tr> ...) to format the data in the bean. There are two for loops that display the the rows (outer loop) and the columns (inner loop).