Ciao a tutti e grazie per la cortese attenzione.
Dunque: implementando un po' di ajax in una webapp mi succede la seguente cosa: quando vado a farmi stampre in un allert la risposta generata dall' action, non mi da risultato( mi da null!!)... cliccando su l' ok dell' allert, prosegue nell' elaborazione e ricarica una seconda pagina che dovrebbe essere la parte di jsp che voglio ricaricare...
Vi posto il codice sperando che qualcuno sia in grado di darmi una indicazione...
"<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix = "ww" uri = "/webwork" %>
<html>
<head>
<title>Calcolatrice</title>
<script LANGUAGE="javascript">
<%-- Inizio Ajax --%>
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
alert(strURL);
self.xmlHttpReq.open('post', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
alert("la risposta e' "+self.xmlHttpReq.responseText);
updatepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(getquerystring());
}
function getquerystring() {
var form=document.forms['inserisci'];
var int1=form.int1.value;
var int2=form.int2.value;
var codOp=form.codOp.value;
qstr='int1=' + escape(int1) + '&int2=' + escape(int2) + '&codOp=' + escape(codOp);
return qstr;
}
function updatepage(str){
document.getElementById("visualizza").innerHTML=str;
<%-- MM_showHideLayers("visualizza","","show");--%>
}
<%-- Finisco Ajax --%>
<%-- Funzione per nascondere/vedere un messaggio --%>
function MM_findObj(n, d) { //v4.0
var p,i,x;
if(!d)
d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document;
n=n.substring(0,p);
}
if(!(x=d[n])&&d.all)
x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++){
x=d.forms[n];
}
for(i=0;!x&&d.layers&&i<d.layers.length;i++){
x=MM_findObj(n,d.layers.document);
}
if(!x && document.getElementById)
x=document.getElementById(n);
return x;
}
function MM_showHideLayers() {
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3){
if ((obj=MM_findObj(args))!=null) {
v=args[i+2];
if (obj.style) {
obj=obj.style; v=(v=='show')?'visible'
v='hide')?'hidden':v;
}
obj.visibility=v;
}
}
}
<%-- Fine funzione --%>
function submitAjax() {
MM_showHideLayers("visualizza","","show");
xmlhttpPost('clientCalcolatrice.action');
}
</script>
</head>
<body>
<form name="inserisci" action="./clientCalcolatrice.action" method="put" >
<table>
<tr>
<th colspan="7" >Inserire i numeri su cui operare</th>
</tr>
<tr>
<td><input type="text" name="int1"></td>
<td><input type="text" name="int2"></td>
<td>
<button name="codOp" value="1" onclick="JavaScript:submitAjax();">Somma</button>
<%-- type="submit"--%>
</td>
<td>
<button name="sub" value="2" onclick="JavaScript:submitAjax();">Sottrazione</button>
<%-- type="submit"--%>
</td>
<td>
<button type="submit" name="mul" value="3">Moltiplicazione</button>
</td>
<%-- <td>--%>
<%-- <button type="submit" name="codOp" value="4">Divisione</button>--%>
<%-- </td>--%>
<td>
<button type="submit" name="pot" value="4">Elevamento a potenza</button>
</td>
<td>
<button type="submit" name="fat" value="5">Fattoriale</button>
</td>
</tr>
</table>
</form>
<div id="visualizza" >
<table border="2" bordercolor="blue">
<tr>
<td colspan="7"><h1>Il risultato della somma di (<ww
roperty value="int1"/>+<ww
roperty value="int2"/>) e' : <ww
roperty value="ris"/></h1></td>
</tr>
</table>
</div>
</body>
</html>"
Dunque: implementando un po' di ajax in una webapp mi succede la seguente cosa: quando vado a farmi stampre in un allert la risposta generata dall' action, non mi da risultato( mi da null!!)... cliccando su l' ok dell' allert, prosegue nell' elaborazione e ricarica una seconda pagina che dovrebbe essere la parte di jsp che voglio ricaricare...
Vi posto il codice sperando che qualcuno sia in grado di darmi una indicazione...
"<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix = "ww" uri = "/webwork" %>
<html>
<head>
<title>Calcolatrice</title>
<script LANGUAGE="javascript">
<%-- Inizio Ajax --%>
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
alert(strURL);
self.xmlHttpReq.open('post', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
alert("la risposta e' "+self.xmlHttpReq.responseText);
updatepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(getquerystring());
}
function getquerystring() {
var form=document.forms['inserisci'];
var int1=form.int1.value;
var int2=form.int2.value;
var codOp=form.codOp.value;
qstr='int1=' + escape(int1) + '&int2=' + escape(int2) + '&codOp=' + escape(codOp);
return qstr;
}
function updatepage(str){
document.getElementById("visualizza").innerHTML=str;
<%-- MM_showHideLayers("visualizza","","show");--%>
}
<%-- Finisco Ajax --%>
<%-- Funzione per nascondere/vedere un messaggio --%>
function MM_findObj(n, d) { //v4.0
var p,i,x;
if(!d)
d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document;
n=n.substring(0,p);
}
if(!(x=d[n])&&d.all)
x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++){
x=d.forms[n];
}
for(i=0;!x&&d.layers&&i<d.layers.length;i++){
x=MM_findObj(n,d.layers.document);
}
if(!x && document.getElementById)
x=document.getElementById(n);
return x;
}
function MM_showHideLayers() {
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3){
if ((obj=MM_findObj(args))!=null) {
v=args[i+2];
if (obj.style) {
obj=obj.style; v=(v=='show')?'visible'

}
obj.visibility=v;
}
}
}
<%-- Fine funzione --%>
function submitAjax() {
MM_showHideLayers("visualizza","","show");
xmlhttpPost('clientCalcolatrice.action');
}
</script>
</head>
<body>
<form name="inserisci" action="./clientCalcolatrice.action" method="put" >
<table>
<tr>
<th colspan="7" >Inserire i numeri su cui operare</th>
</tr>
<tr>
<td><input type="text" name="int1"></td>
<td><input type="text" name="int2"></td>
<td>
<button name="codOp" value="1" onclick="JavaScript:submitAjax();">Somma</button>
<%-- type="submit"--%>
</td>
<td>
<button name="sub" value="2" onclick="JavaScript:submitAjax();">Sottrazione</button>
<%-- type="submit"--%>
</td>
<td>
<button type="submit" name="mul" value="3">Moltiplicazione</button>
</td>
<%-- <td>--%>
<%-- <button type="submit" name="codOp" value="4">Divisione</button>--%>
<%-- </td>--%>
<td>
<button type="submit" name="pot" value="4">Elevamento a potenza</button>
</td>
<td>
<button type="submit" name="fat" value="5">Fattoriale</button>
</td>
</tr>
</table>
</form>
<div id="visualizza" >
<table border="2" bordercolor="blue">
<tr>
<td colspan="7"><h1>Il risultato della somma di (<ww



</tr>
</table>
</div>
</body>
</html>"