Starting With GlassFish – Part 2, The Web Page

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">
    <input type="button" onclick="callMyCode()" value="Upload"/>
</form>

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.

The other articles in this series can be found here.

Related Posts:

Download our free PDF Guide for Java Developers

This entry was posted in Extraction, glassfish, html, Java, PDF and tagged , , , . Bookmark the permalink.

Comments are closed.