Las relaciones entre los parámetros JSP y HTML

a thoretical question: my button gets its initial value from the var "message" defined at the beginning of my JSP file. lets say the value of "message" is changing later. how can i make my button's value tag updated too?



String message = "Hello!"


cuerpo html:

<input id="mybutton" type="button" value="<%=message%>/>

preguntado el 29 de julio de 12 a las 02:07

2 Respuestas

You will have to change the variable to its final value before the variable is rendered. If you want to update a value on the web page using server data after it has been rendered you can either refresh the page or make an ajax request to the server to retrieve the latest data. Do a Google search for jQuery and Ajax for more information on how to do this.

Here's an article to get you going:

Implementación de Ajax en una aplicación web Java usando JQuery

Respondido 29 Jul 12, 02:07

The scriptlet runs before the Javascript even executes. So what you would do is

var message = <% "Hello" %>

So this line create a Variable de JavaScript, message, that has a value that is set when the jsp is evaluated.

obviously, this example is silly, but if you replace hello with some variable in Java-land, it's much more useful.

Also note, that you can't update a value with a scriptlet after the page is rendered. You will have to use Ajax.

Respondido 29 Jul 12, 02:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.