|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Jul 2005
Messaggi: 584
|
[javascript] problema assegnazione variabile
Ciao,
ho una pagina jsp, di cui riporto il codice, in cui c'è la funzione myFunction() che dopo aver fatto session.getAttribute("test") richiama la servlet NewServlet nella quale tramite String s = (String) session.getAttribute("test") recupero il valore di test. Così funziona correttamente, il problema è quando provo a voler assegnare a String text il valore di myvar con String text = myvar; oppure String text = String (myvar); ottendendo l'errore riportato. Potete per favore indicarmi come fare ? Sono le prime volte che utilizzo javascript e servlet. Grazie ![]() Errore HTTP Status 500 - Unable to compile class for JSP: org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 14 in the jsp file: /Test.jsp myvar cannot be resolved to a variable 11: 12: function myFunction() { 13: <% 14: String text = myvar; 15: session.setAttribute("test", "1234567890"); 16: %> 17: codice pagina Test.jsp <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Test</title> <script type="text/javascript"> var myvar="hello world"; function myFunction() { <% String text = "prova"; session.setAttribute("test", "1234567890"); %> var someText = "<%=session.getAttribute("test")%>" document.location.href = '${pageContext.request.contextPath}/NewServlet'; } </script> </head> <body> <h1>Hello, world!</h1> <button onclick="myFunction()">Try it</button> </div> </body> </html> |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 07:35.