I have recently begun experiements with glassfish with the idea of creating a few web pages that use glassfish to call some of jPedals example code (such as our PDF to HTML5 converter) and provide the user with the output. During my research I found various examples and tutorials that were meant to help beginners but as I knew nothing of glassfish and haven’t written any serious html for about 5 years I was having trouble understanding some unfamiliar concepts.
These blog articles will cover the concepts I had to learn in order to get my example working. This article will cover the servlet.
First thing we need for the servlet is to create a class that will be the starting point for any calls from the web page we will create later. I found that things work best if you have a class to recieve requests from the web page and pass on the requests to the correct bean based upon the path passed in. In a class like this we can define multiple paths that can return different beans. To define paths you use the following line.
These should be put above the start of the class and at the line above the various methods that return bean you wish to use. The beans that you return here should be defined with @EJB at the begining like so
@EJB MyResourceBean b;
Within these beans we can define methods that we bind to various html commands such as POST and GET. We bind these commands to the methods within a bean by adding a line for the given html command above the method for example
Knowing this you can now start writing code to be run on a glassfish server and set out how the various methods can be called.
The next blog in the series will show how to set up the webpages ready to call the required servlet methods.
This post is part of our “GlassFish Articles Index” series. In these articles, we aim to explore Glassfish in different ways, from useful tutorials, to JaveOne and general.