• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt regarding javascript behaviour

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Arthur, where are your pants? Check under this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic