Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt regarding javascript behaviour

 
rachana ravali
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

i am new to javascript.
i want to set the value of a java variable using the value of a javascript variable.

For example iam writing a function like below:
function test()
{
var test = true;

if(test== true)
{
<% System.out.println("in true");%>
}else if(test == false)
{
<% System.out.println("in false");%>
}
}

here even if the value of test is true ,the code inside the conditional block false is also executed.

i want to know whether we can set variables using conditional blocks using java script.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with how JavaScript works but rather, with how the JSP scriplets in your page work.

These scriplets are executed on the server long before the page is sent to the client and the Javascript executes.

This is a critical comcept for you to understand if you are going to be working with JSPs. Please read this article for help in understanding these concepts.
 
rachana ravali
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much for the link you have gave me Bear Bibeault .
So there is no way to initialize a java variable using a javascript right ?
Please help me if there is any way.
Also can you tell me whether we can maintain the java script variables in session ?

thanks in anticipation.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by rachana ravali:
thank you very much for the link you have gave me Bear Bibeault .
So there is no way to initialize a java variable using a javascript right ?
Please help me if there is any way.


Please read the article again. Asking if there is a way indicates that you did not quite understand it.

Also can you tell me whether we can maintain the java script variables in session ?


Only by submitting those values to the server in some way (link, post, Ajax) and have server-side code store the values. You could then restore them during a page refresh or Ajax call.

But as the article points out, JavaScript and server-side code live in different worlds and cannot directly communicate.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic