Grossa Crisi!!!!

giano1975

Nuovo Utente
12 Mag 2006
7
0
0
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:property value="int1"/>+<ww:property value="int2"/>) e' : <ww:property value="ris"/></h1></td>
</tr>
</table>
</div>
</body>
</html>"
 

giano1975

Nuovo Utente
12 Mag 2006
7
0
0
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 submitAjax() {
MM_showHideLayers("visualizza","","show");
xmlhttpPost('clientCalcolatrice.action');
}

La uri per me è la chiamata alla action che come vedi gli passo da js in questa funzioncina che poi mmi richiama quella sopra...

Inoltre nel fare un po' di prove, mi sono fatto stampare i self.xmlHttpReq.readyState in un alert ed ho scoperto che salta il 3, quindi i dati NON stanno arrivando a destinazione...

Il problema è tutto qui, visto che le altre funzioni eseguono bene i loro compiti.

Grazie ancora per l' attenzione, io.
 

giano1975

Nuovo Utente
12 Mag 2006
7
0
0
clientCalcolatrice.action

questo è un file?

é la classe che mi fa da action...

immagino che il server sia linux, quindi fossi in te verificherei che un qualsiasi script che usa xmlhttp funzioni

il server è weblogic e lavora in ambiente windows.
inoltre su questo server ho già implementato ajax( non so bene se sto rispondendo alla seconda affermazione) e tutto funziona correttamente.

il problema riscontrato è che la prima jsp contatta la mia servlet( la action di cui sopra) e passa i dati correttamente, vengono elaborati e restiuiti.
viene attivata la jsp in cui metto la parte di pagina che voglio ricaricare e quando questa deve tornare indietro mi torna vuota, come se non ci fosse nulla... :-(

Sono stato esauriente???
 

Discussioni simili