File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Problem in AJAX and JSP data exchange Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in AJAX and JSP data exchange" Watch "Problem in AJAX and JSP data exchange" New topic
Author

Problem in AJAX and JSP data exchange

chetan sisodiya
Greenhorn

Joined: Nov 14, 2011
Posts: 12
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

Joined: Mar 24, 2008
Posts: 3775

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.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in AJAX and JSP data exchange
 
Similar Threads
A problem in hiding a button
Ajax + struts
Java Dynamic Servlet
Simple AJAX query what I'm missing?
Copying code from .html to .jsp produces unexpected results.