0

I was wondering what the difference between declaring a function like this:

<SCRIPT>
    function afunc(){
        x1 = 0;
        //stuff goes here
    }  
</SCRIPT>

and like this:

<%!
    public afunc(){
        x2 = 0;
        //stuff goes here   
    }
%>

Also, what is the scope of x1 and x2? I am trying to access a variable that is similar to x1, somewhere (outside the script tags of x1) in the same .jsp file inside a pair of <% %> and I am not able to do so (probably due to scope problems).

Thanks!

Perplexabot
  • 1,852
  • 3
  • 19
  • 22
  • 2
    One is javascript, the other not. What server-side language are you using (if at all)? – Bergi Feb 24 '14 at 04:32
  • javascript vs jsp. one within SCRIPT tag resides in client another in server. – Peshal Feb 24 '14 at 04:35
  • Hmmmm. Server-side language? Not sure what you mean... All I know is that I am working on .jsp file... Wait so there is a difference between javascript and jsp (i thought they were the same!)? Thanks – Perplexabot Feb 24 '14 at 04:43
  • first of all dont leave your ``. Javascript code gets evaluated on the front-end or your browser... The second one is a scriptlet...it is highly recommended to refrain from using Scriptlets...use jstl or any better alternatives...code in jsp will be evaluated on the serverside – Vikram Feb 24 '14 at 04:47
  • possible duplicate of [javascript and jsp](http://stackoverflow.com/questions/2671642/javascript-and-jsp). Really, they're two entirely different languages in two entirely different environments that have as much in common as "car" and "carpet". They may occur in the same file because the Java code generates HTML markup for the client, which might contain JavaScript. – Bergi Feb 24 '14 at 05:02

0 Answers0