Ajax - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

AJAX With JAVA

AJAX With JAVA

shape Description

Initially Java is called as OAK, in the 1995 it is renamed as Java, as part of Java some modules are there like Core Java is utilized to develop stand-alone applications and it will be in the form of two-tier architecture. Advanced Java is utilized to develop the web applications by using Servlets, JSP and it will be in the form of three-tier architecture. The Java enterprise edition is utilized to develop distributed applications and it will be in the form of the entire architecture. As part of Java JME (Java mobile edition) is utilized to develop mobile applications. The following is the basic code for the Java. [java] Class runs { public static void main(String args[]) { System.out.println("Welcome To Splessons"); } } [/java] Now compile the code result will be as follows. [java]Welcome To Splessons[/java]

Ajax Java Example

shape Description

To build a ajax example with java, user need to write any server-side code such as jsp, servlet etc. JSP stands for Java Servlet Pages and is utilized for server-side technology which is an augmentation of Servlet technology that was created by Sun Microsystem. The servlet will get executed on client browser where as JSP will get executed on the server. JSP is utilized to create dynamic web applications like as a Servlet technology but gives extra functionalities like custom tags, JSTL, expression dialect. JSP concentrates for the most part of presentation logic of the application. Servlet run quicker than JSP, the fundamentally favorable position of JSP is less coding contrasted with servlets. The following is the structure of an example. table1.html [html] <html> <head> <script> var request; function sendInfo() { var v = document.vinform.t1.value; var url = "index.jsp?val=" + v; if (window.XMLHttpRequest) { request = new XMLHttpRequest(); } else if (window.ActiveXObject) { request = new ActiveXObject("Microsoft.XMLHTTP"); } try { request.onreadystatechange = getInfo; request.open("GET", url, true); request.send(); } catch (e) { alert("Unable to connect to server"); } } function getInfo() { if (request.readyState == 4) { var val = request.responseText; document.getElementById('amit').innerHTML = val; } } </script> </head> <body bgcolor="skyblue"> <center> <h1>Welcome To Splessons</h1> <img src="://splesson.png"> </br> </br> <form name="vinform"> <input type="text" name="t1"> <input type="button" value="ShowTable" onClick="sendInfo()"> </form> </center> <span id="amit"> </span> </body> </html> [/html] The onreadystatechange function will be put away and will be called naturally every time readyState property changes index.jsp [html] <% int n=Integer.parseInt(request.getParameter("val")); for(int i=1;i<=10;i++) out.print(i*n+"<br>"); %> [/html] The parseInt() gives back a whole number, given a string representation of decimal, octal, hexadecimal numbers as information. web.xml [html] <?xml version="1.0" encoding="UTF-8" ?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>table1.html</welcome-file> </welcome-file-list> </web-app> [/html] The web.xml document is the arrangement descriptor for a Servlet-based Java web application . In addition to other things, it pronounces which Servlets exist and which URLs that handle. Now compile the code from the html page then the result will be as follows. Now enter any value then multiples of the number will come as follows.

Summary

shape Key Points

  • The session is time oriented if time is completed, then the session will be automatically closed.
  • JSP Session is an implicit object of the type HttpSession.
  • The JSP Session object provides the communication between the server and browser to fetch the data.