4

I have a text field, I need to send these text value to the same page which is in jsp .

I just want to assign javascript value to jsp variable.

2 Answers 2

3

You can't. JSP runs on the server, Javascript runs on the client, so when Javascript runs the JSP variable doesnt exist anymore.

Consider using AJAX.

Sign up to request clarification or add additional context in comments.

Comments

2

You could set a hidden field.

Put this in your JSP form:

<input type="hidden" id="foo" name="foo" />

Execute this script whenever you want to fill the field:

document.getElementById("foo").value = "some value";

When you submit the form, it'll be available as follows in the servlet:

String foo = request.getParameter("foo"); // "some value"
// ...

See also:

1 Comment

request.getParameter() takes a form element and moreover it refreshes the page, is there any other method to achieve this? If i dont wanna use ajax...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.