0% found this document useful (0 votes)
38 views2 pages

HTML Head Script: Var Function Var Var If New Else If New

The document contains code for an AJAX application that uses JavaScript and XMLHttpRequest to send a GET request to a JSP page without refreshing the HTML page. The JSP page multiplies the GET parameter by numbers 1 through 10 and returns the results as a string. This string is then inserted into a span element on the HTML page using innerHTML.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

HTML Head Script: Var Function Var Var If New Else If New

The document contains code for an AJAX application that uses JavaScript and XMLHttpRequest to send a GET request to a JSP page without refreshing the HTML page. The JSP page multiplies the GET parameter by numbers 1 through 10 and returns the results as a string. This string is then inserted into a span element on the HTML page using innerHTML.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Newfile.

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('file1').innerHTML=val;
}
}

</script>
</head>
<body>
<marquee><h1>This is an example of ajax</h1></marquee>
<form name="vinform">
<input type="text" name="t1">
<input type="button" value="ShowTable" onClick="sendInfo()">
</form>

<span id="file1"> </span>

</body>
</html>

Index.jsp
<%@ page import="java.sql.*"%>
<%
int n=Integer.parseInt(request.getParameter("val"));
for(int i=1;i<=10;i++)
out.print(i*n+"<br>");
%>

Web.xml

<?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>NewFile.html</welcome-file>
</welcome-file-list>
</web-app>

You might also like