1

Would like to know the ways to update the session variable in JavaScript function when the submit button is clicked and the same variable to be accessed in controller class.

The below links provides information on setting session variable in function

Pass Javascript Value to Java in JSP

and

JSP - how to pass a javascript var in session.setAttribute?

But, I need to update session variable only when the checkbox is selected and pass to java controller on form submission.

1
  • Hi and welcome to the site. Please see How to Ask for how to ask a useful question. Commented Apr 12, 2017 at 12:43

2 Answers 2

0

The session variable in javascript function can be updated only if you update the variable on the server. But since the javascript is executing in the browser you can't update the session variable.

Then you need update the page where this session variable is used.

If you can't update the part of the page and need to update the whole page to make changes effective then send redirect result with the response that refreshes the page. It will reinitialize the javascript with the variable in session.

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

2 Comments

Thank you for the guidance.
@Divya You can accept the answer that helped you. See stackoverflow.com/tour
0

The first part of your question , as i understand you are trying to update the session from javascript , you can do an AJAX call to the action form and update the session variable as you usually do in Struts 2 , the page won't refresh .

1 Comment

I got the element by using document id in function and set the value and fetched the variable in java controller class by using request parameter. Thanks.

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.