Como ejercicio, estoy tratando de crear una página simple en la que tenga dos cotizaciones de acciones, configuradas con los valores iniciales 100 y 200. Los métodos updateValues() modifican el valor de la cotización en +/-1% y el método displayAction() regresa la Cadena "<nombre de la cotización> = <valor de la cotización>". De todos modos, si hago clic en el botón "Actualizar valores", las dos cotizaciones no cambian. ¿Qué estoy haciendo mal?
Aquí está mi index.jsp:
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <jsp:useBean id="enel" class="it.unitn.studenti.porcelli.leonardo.esamefebbraio2022.businessobject.Enel" scope="application"></jsp:useBean> <jsp:useBean id="webuild" class="it.unitn.studenti.porcelli.leonardo.esamefebbraio2022.businessobject.WeBuild" scope="application"></jsp:useBean> <!DOCTYPE html> <html> <head> <title>PWEB Banking</title> </head> <body> <script> function startIsClicked(){ document.querySelector("#start_button").disabled = true; document.querySelector("#stop_button").disabled = false; } function stopIsClicked(){ document.querySelector("#start_button").disabled = false; document.querySelector("#stop_button").disabled = true; } function refreshValues(enel, webuild){ const xhttp = new XMLHttpRequest(); xhttp.onload = function (){ const newEnelValue = <%enel.updateValue();%>; document.getElementById("Enel").innerHTML = enel.displayAction(); const newWebuildValue = <%webuild.updateValue();%>; document.getElementById("Webuild").innerHTML = webuild.displayAction(); } xhttp.open("GET", "index.jsp", true); xhttp.send(); } </script> <div id="buttons"> <button id="start_button" type="button" name="start" onclick="startIsClicked()">Start</button> <button id="stop_button" type="button" name="start" onclick="stopIsClicked()" disabled>Stop</button> </div> <div id="Enel"> <%=enel.displayAction()%> </div> <div id="Webuild"> <%=webuild.displayAction()%> </div> <button type="button" onclick="refreshValues(<%=enel%>, <%=webuild%>)">Refresh Values</button> <br/> </body> </html>