Developing with SAP NetWeaver Developer Studio | Developing MI Applications | Example 2 JSP | Example 3 JSP | Example 1 AWT
In this 1st example program, a basic servlet reads data from the
MI Client configuration into a bean and calls a JSP to display the information
about the MI client installation.
This example demonstrates how to use the AbstractMEHttpServlet package, put
a bean in the session context and call a JSP.
To download the example program, click here
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 |
tableView.jsp | JSP to display the information. |
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:
Now the JSP is called and the data is displayed on your web browser.
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.
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.
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).