Thursday, May 1, 2014

Developing Web Application Using Jaggery - Part 2

This is part 2 of a series of Jaggery tutorials. This post explains the syntax of Jaggery and how to develop a simple application using Jaggery. 

Please go through part 1, Developing Web Application Using Jaggery - Part 1, if you don't know about Jaggery, how to install it, run it etc.

 

Jaggery Syntax 

Jaggery file extension is .jag (like Java file extension is .java)

The following is the syntax of Jaggery.



Everything wrapped between <% %> is Jaggery code. It means that everything wrapped by <% %> runs on server.

The print(msg); method outputs a server side variable to the document.

.jag file can contains HTML code. The above code can be written as below, 


Create a directory "myApp" and save the above file as "index.jag" inside "myApp" directory. 

You have successfully created your first Jaggery App.

Let's deploy it. If you don't know how to deploy it, please refer to part 1 of this series.

Copy myApp directory to Jaggery deployment directory which is JAGGERY_HOME/apps. 

Let's start the server. If you don't know how to start the server, please refer to part 1 of this series.

Run sh JAGGERY_HOME/bin/server.sh ( JAGGERY_HOME/bin/server.bat in windows) command to start the server.

Let's access your myApp application. Point the browser URL to http://localhost:9763/myApp/. You will have your myApp up and running.

Let's learn some more built-in functions as we need those functions in our part 3 of this series.

request

This is an object which holds properties and functions regarding the HTTP request that the client made to the server.

For example, 

getRemoteAddr() - returns client's IP
getMethod() - returns type of request

For more information, please refer here


session

This is an object which holds properties and functions regarding the current session of a client.

For example, 
invalidate() - destroy the session

For more information, please refer to here

application

This is an object which holds properties which are global to the entire application instance.

For example, 
put('propName', value) - saves the value in the name of probName.

For more information, please refer to here.

I guess these are enough for next part of this series.

Develop a sample e-banking application using Jaggery




No comments:

Post a Comment