Kieran France Kieran France is a programmer for IDRSolutions. He enjoys tinkering with most things including gadgets, code and electronics. He spends his time working on the the JPedal library and our internal test suite..

Starting with GlassFish – Part 1, The Code

1 min read

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.

@Path("/methodPath/")

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

@Post

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.

The next article in this series is about the Web Page, and can be found here. To view all articles, click here

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.

Kieran France Kieran France is a programmer for IDRSolutions. He enjoys tinkering with most things including gadgets, code and electronics. He spends his time working on the the JPedal library and our internal test suite..

Leave a Reply

Your email address will not be published. Required fields are marked *