0

I have this code:

<script type="text/javascript">
  function foo() {
     var test =///value;
    <!--and i jave java code inside this script!--> 
    <% String str= // i want to assign it to test value%>

  }
</script>  

How can i assign test to str ??

0

1 Answer 1

2

How can i assign test to str ??

No simply you cannot.

Java plays on server side and javascript on server side. A client doesn't execute the java code.

You can assign a java value to javascript variable with jsp or Expression language on server side.

To send a javascript value to java you have to make a server request, So the server process your string and send the results back to client.

Most probably you are looking for AJAX request.

Do not confuse that JSP and java script existed on same document(or file). Yes but JSP part compiles on server side and JavaScript executes by browser.

A clear cut example found here for a start.

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

1 Comment

so how i can sent selected value from checkbox to string value??

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.