This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in AJAX and JSP data exchange

 
chetan sisodiya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FILE NAME - aja1.jsp
I am using AJAX for sending parameter on the same page using GET Method.

How can I process those parameter in my JSP code and get back the resuld in responseText Object.
Forexample - In PHP we can echo pramater to access by responseText Object.

My code is given below...



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function sendparm(){


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)
{
var ajaxDisplay = document.getElementById('aj_id');
ajaxDisplay.innerHTML = ajaxRequest.responseText;

}
}
var nm= document.form1.txt1.value;
var url = "aja1.jsp"
var queryString= "?name=" + nm;
xmlhttp.open("GET",url+queryString,true);

xmlhttp.send(null);
}
</script>
<title>JSP Page</title>
</head>
<body>



<form name="form1" method="get" action="aja2.jsp" value="form1">
<input type="text" value="" name="txt1"></input>
<input type="button" value=click" name="btn1" onclick="sendparm()"></input>

<%
String str = request.getParameter("name");
//////WHAT SHOULD I DO NOW TO PROCESS THIS STR VARIABLE AND TO ACCESS IN AJAX TO INSERT IN HTML
%>

</form>

<div id='aj_id'>Your result will display here</div>

<input type="text" value="" id="asdaasd" name="txt2"></input>

<h1>Hello World!</h1>
</body>
</html>
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you read a basic tutorial about AJAX.

And please make sure to use code tags when posting code in the forums. Unformatted code make it harder to read the content.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic