Using AJAX with JSP

Hi

I m using AJAX with jsp. In my code call the ajax function on the onChangeEvent of combo as

<select id='combo1' name="ProcessCombo" onchange="ajaxFunction(this);">

I am setting ajaxRequest.responseText to the div tag named as subtab2

function ajaxFunction(process){

var ajaxRequest; // The variable that makes Ajax possible!

try{// Opera 8.0+, Firefox, Safari

ajaxRequest = new XMLHttpRequest();

} catch (e){

// Internet Explorer Browsers

try{ alert("Internet");

ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

try{ alert("Internet Catch block");

ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

} catch (e){

// Something went wrong

alert("Your browser broke!");

return false;

}

}

}

var combo = document.getElementById('combo1').value;

var queryString = "?comboVal=" + combo;

alert(queryString+ " readyState "+ajaxRequest.readyState);

// Create a function that will receive data sent from the server

ajaxRequest.open("GET", "processInfo1.jsp" + queryString, true);

ajaxRequest.send(null);

ajaxRequest.onreadystatechange = function(){

if(ajaxRequest.readyState == 4){

//document.Process.time.value = ajaxRequest.responseText;

//document.Process.processVal.value = ajaxRequest.responseText;

var ajaxDisplay = document.getElementById('subtab2');

ajaxDisplay.innerHTML = ajaxRequest.responseText;

}

}

}

The div tag is as

<div id="subtab2">

<Table align="center" border="0" cellpadding="1" cellspacing="1">

<TR>

<%

System.out.println("@@@@@!!!! "+process);

try{

// String abc="LATimes";

enumJ1 = comm.getTransInfo(process);

System.out.println("Size....."+enumJ1.size());

System.out.println("aa1........");

}catch(Exception ex){

out.println("#@@#Exception caused " + ex);

}

%>

<td width="10%">Software Group牋牋</td ><%

try{

System.out.println("aa2........");

for (int k=0;k < enumJ1.size () ;k+=3 )

{

System.out.println("aa3 In loop........");

grpcode = (String)enumJ1.elementAt(k);

out.println(" grpcode: "+grpcode);

grpDescr = (String)enumJ1.elementAt(k+1);

//out.println(" grpDescr: "+grpDescr);

//System.out.println("111rate: "+rate);

//comm.addRate(rate);

System.out.println("aa4........"+grpDescr);

// sGroup=grpcode;

%><input type="button" value="<%=grpDescr%>" name="<%=grpcode%>" >

</tr>

</table>

</div>

<% System.out.println("aa5........");

}

}catch(Exception e){

System.out.println("Exception is..."+e);

}

//sGroup=grpcode;

%>

In this it doesn抰 show button but there are no any errors .All the code goes welll it shows the ideal processing in log file.Can抰 understand wht is the problem..?

Thanks in advance,

Meghna

[3144 byte] By [Meghnaa] at [2007-11-27 6:19:22]
# 1
May be JSP is already rendered, it couldn't reconize the DIV tag? you're calling JSP page within AJAX request. Why don't you call an acitonclass and get the result in your AJAX callback fn, and display. I can send you the code later.
skp71a at 2007-7-12 17:33:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

function myAJAX(string1) {

var URL = "requiredAction.do";

var queryString = "name="+escape(string1);

httpObject.open( "Post", URL, true );

httpObject.onreadystatechange = callBackFn;

httpObject.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );

httpObject.send(queryString);

}

function callBackFn() {

if (httpObject.readyState == 4)

{

if (httpObject.status == 200)

{

var result = httpObject.responseText;

//code here to manipulate result

}

}

}

skp71a at 2007-7-12 17:33:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
To use Ajax with JSP, use the AjaxTags framework. http://www.itarchitect.co.uk/articles/display.asp?id=335
dvohra09a at 2007-7-12 17:33:50 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...