How to access objects in server from javascript namespace:
case study - how to indicate "the shelves are empty in an e-shop"? (under construction)
A. Introduction (problems/issues): Show detailsTo build an "AJAX application", one of the major design issues you face after loading a page is "how to access backend objects from javascript namespace where you make ajax calls?". Issues involved:
- which server target to call
There are a variety of targets could be called/invoked and different result could be returned. (See details in next section).- Session maintenance
In most cases, your AJAX calls participate as a part of a http session. If you track your sesssion, you may see that each of your AJAX requests create its own session in case you use AJAX "as default". The fact is simple: there won't be session hooking if your AJAX requests don't contain session info.- Session timeout notification
See detail discussion at How to notify session timeout with AJAX
B. Solution/approaches: Show detailsThe goal of the page is to illistrate a variety of approaches to make calls to server:
- Spring MVC standard call
In this approach, the ajax makes calls to controllers in Spring MVC. The controllers in turn access database through JDBC DAO and return jsp views. This is a very "default" approach in Spring MVC environment. The advantage is that it used the common seqence that can be shared by other type of requests. The drawback is that it is done in a heavy way where a complicate series of dispatching and forwarding is performed only for such a single field change and for a tiny data return.- JSON RPC
In this approach, the javascript object make rpc calls to correcsponding java objects(beans) to request db update. The respond of the request update the requster (the javascript object). The advantage is that it is very light way and hooks Javascript objects directly to backend Java Objects. The update is done is a synchronized way to compare with the asynchronized one above. I used jsonrpc-spring from Aldrin Edison Baroi to integrate JSON-RPC into Spring.
C. Project structure: Show detailsspringapp (url: http://remotescriptguru.com/springapp) is a Spring application with following architecture: a. application tier - Spring MVS b. business tier - JDBC DAO Hibernate (under construction) c. batabase - MySQL
D. Case Study (running codes): how to indicate "the shelves are empty in an e-shop" Show details