Developing with SAP NetWeaver Developer Studio | Developing MI Applications | Example 1 JSP | Example 2 JSP | Example 1 AWT
The 3rd example program extends the second by adding multi-language support to it through the usage of resource bundles. The coding of this example is exactly the same as in the 2nd example program. The only difference are the resource bundles. We use the wizards of SAP NetWeaver Developer Studio to create the resource bundles. See Internationalization for more information how to create resource bundles from an existing Java file.
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, JSP and propertz files 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. |
Messages.java | Set up of the resource bundles and handling the exception. |
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 |
configExampleResBundle.properties | Default resource bundle for German language. |
configExampleResBundle_de.properties | Resource bundle for German language. |
JSP |
Description |
welcome.jsp | Initial JSP displaying an input field and a submit button. |
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:
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.
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.
welcome.jsp
Displays a welcome message and allows to enter a user name. The JSP contains
a "Submit" button to send the page. Besides the dataBean it also retrieves
the resource bundle object and uses it to get the resource bundle strings.
|
An interesting JSP related phenomenon: |
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).