What is a servlet?
Servlets are Java classes which service HTTP requests and implement the ‘javax. servlet. HttpServlet’, an abstract class that implements the servlet interface and is specially designed to handle HTTP requests.
A servlet accepts the request, processes it, creates a data package, and serves it as response.
Processing usually includes access to databases, fetching data and conversion to object models of convenience. Objects can be JSON, XML, reports, or files exported to a hard disk.
Examples of custom servlets in Maximo are showing images, print attachments, print BIRT reports, export integration files, REST integration, REST token authentication or print various other documents.
A custom servlet usage scenario
To demonstrate the use of a custom servlet, I will show an example of its use in Maximo.
First, let us imagine a scenario where this servlet will be used:
As a part of RFQ process, a user wants to export quotation lines into a file and send it to the vendor. The user wants to minimize possibilities of error while populating data.
For that purpose, we will create an excel file with extra twists. This includes:
- vendor specific passwords on the excel sheet,
- some fields set as read only,
- fields set as calculated, and
- fields that have domains in Maximo which will have attached drop down lists with domain values.
This way, vendors only have to populate editable fields quantity and unit cost.
The user wants the action to be triggered at a certain point, through a download button or as a part of the WF process.
How is a custom servlet implemented?
In RFQAppBean we will create an event/method that looks like this:
At some point, while in RFQ application, with relevant RFQ displayed, ‘download event’ will be triggered.
The event will store RfqNum in session and invoke a servlet.
The second step is to define the servlet in web.xml.
Lines to be added are:
The final step is to create a custom class for the servlet. A custom class would look like this:
We are using HSSF (or XSSF) excel library to create an excel workbook from scratch. Creation logic is encapsulated within class ‘RFQLinesDownload()’.
Eventually, the workbook will be streamed to a response. As you can see the output will be a real excel file (not csv).
This is just one example of custom servlet usage among many possibilities. Implementing functionality is relatively easy. There are many ways to use it and they are limited only by your (and your client’s) imagination.
And at the end, here are some bonus excerpts from the ‘RFQLinesDownload()’ class:
How to put a password on excel sheets:
How to create a calculated field:
Finally, click here if you would like to learn more about Maximo in one of my previous blog posts ‘Maximo and Attachments’.
If you would like to learn more about features of Maximo that BPD Zenith can offer, you can contact us at: https://www.bpdzenith.com/asia/contact/