开发者

Ajax call to call jsp [closed]

开发者 https://www.devze.com 2023-03-14 14:36 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.开发者_运维百科

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消