Reputation: 6612
This is my java class:
package org.at.network;
public class MyClass {
public static enum Type {
ROOT(0),RELAY(1),LEAF(2),NULL(3);
private int value;
Type(int value){
this.value = value;
}
public int getValue(){
return value;
}
}
....
Now in my jsp:
<%@page import="org.at.network.MyClass"%>
var ROOT = <%=MyClass.Type.ROOT.name() %>;
How come it gives me:
Uncaught ReferenceError: ROOT is not defined
?
If I execute that code in a java class it works so it should be a jsp problem...
Upvotes: 1
Views: 310
Reputation: 17595
I think it's a javascript problem...
Probalby the javascript code that is generated looks like this:
var ROOT = ROOT;
so at this point the variable ROOT
is undefined.
You probably wanted to save it as string:
so try doing:
var ROOT = '<%=MyClass.Type.ROOT.name() %>';
doing so the js code generated will be
var ROOT = 'ROOT';
Upvotes: 1