Ajax is used to update the parts of the web page with out reloading the entire page.
JSON is used to store and exchange the data between client and server.
Enums is used to store the data means a list of named constants.
In this example, Data will be loaded into drop down list based on the selected option(country) using Jquery and the above mentioned technologies.
Unlike JSP's , we can make use of HTML itself by using JSON concept for data exchange between client and server.
Ajax and its terms:
type : Type of request eg: get, post
url : The URL to which the request has to sent,Typically Servlet or JSP.
data : An object or string that is sent to the server with the request.
Success : A callback function that is executed if the request succeeds.
Error : function called When request completes with an error
Ajax Request will call servlet post method, Flag was used to separate from multiple requests. Based on that it will call corresponding method in java.
In this code fragment,Used two enumerations to hold the data,instead of getting data from Database. Here based on selected country ,iterating the corresponding enumeration and creating JSON object and adding that to JSON array and sending the JSON array as a response.
jar files used for smooth flow:
Apache tomcat v7.0