• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Problem in AJAX and JSP data exchange

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic