Peripheral Input/Output Services
This example uses the PIOS Print API to print a text string. The
emulator has to be started before this example - otherwise you get an exception.
The example defines two objects that have a 1:1 relation. As typical 1:1 relation we haven chosen a "car" : "license"(number) scenario. The example demonstrates how the Persistence API has to be set up and how to read and write data. The MDK provides a template for this example. Click here to Download template.
The example uses following packages:
import com.sap.ip.me.api.pios.connection.*
import com.sap.ip.me.api.pios.printer.*
Java - default package |
Description |
PrintServlet.java | Implementation of the servlet. |
Constants.java | Interface defining all text strings used in PrintServlet.java. |
Java - bean package |
Description |
dataBean.java | Implementation of the bean that is loaded by the servlet and read by the JSP. |
JSP |
Description |
printer.jsp | JSP that prints the text string. |
The PrinterServlet.java fills the bean with a welcome message and calls printer.jsp. printer.jsp uses the PIOS print API to print a text string.
We create a class PrinterServlet 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 PrinterServlet you will find the definition in interface Constants.
The class PrinterServlet extends AbstractMEHttpServlet which extends javax.servlet.http.HttpServlet itself. The application is separated into the default package (containing all classes necessary to interact with the user), the bean (which contains the bean which serves as data bag between the servlet and the JSP).
default package
The bean serves as data bag. It has a string, a vector and two variables that define the length and width of the string array. All variables have get and set methods.
printer.jsp
The JSP creates a GraphicPrinter object, gets a Connector
instance and uses the PIOS methods to print a text string on a defined position.