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 2, The Web Page

1 min read

This is part 2 in this series of blog articles. To read part 1 to learn about the code, please click here.

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 html code.

The first thing we need to do is create a script that will allow us to interact with a servlet. For example I have created a javascript script below. In the script we have a function called callMyCode that creates a request, opens a connection to the given point in the servlet with a given command and sends any data, in this case null.
The following script will call the POST method found in the bean pointed to by the path /methodPath/methodName

function callMyCode() {
    xhr = XMLHttpRequest();
    xhr.open("POST","methodPath/methodName/",true);
    xhr.send(null);
}

Now we have a script to call our servlet we need some way of activating the script. This could be called in one of many different ways. The following example is a button that calls the above function.

<form enctype="multipart/form-data" method="post">
    

We now have the basics of what you need in your html code to allow the web page to call your servlet and perform any actions we place in the given 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.

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 *