I have a html file. On submission of form i need to call a jsp & jsp should return any boolean value to the calling html page.
Please suggest the code.
Thanks in advance Tanu
Actually i m working on contactus form. There is an html page for UI form.and on submit of this form it should call a jsp which should return on that html.Because if i will call jsp then on every refresh it will send an email which i dont want.
Please suggest.
Actually we can't write your full code but we can try to help you when you have a problem. A good starting point for you could be here and i also suggest you use jQuery to ease cross-browser problem for AJAX requests
Here Html page will look like this
<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.jsp",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>
</body>
</html>
Jsp page will be like this -- ajax_info.jsp
<%@ page language="java" import="java.util.*" errorPage="" %>
<% boolean myInfo = false; %>
<%=""+myInfo%>
don't use any html tags in jsp page which is ur calling from ajax.
I would not call a JSP when using AJAX since JSP are best suited for viewing purposes (i.e. rendering HTML, or XML).
I would suggest you using a plain servlet. Here's a simple tutorial on how to use AJAX with plain Servlets.
If you still want to call JSP with your AJAX request you can still do that. Just point your AJAX request to your proper JSP URL.
精彩评论