Search code examples
javajspjakarta-eeweblogicweblogic11g

How do you force Weblogic to print "null" in jsp files, rather than empty string "", for variables with null as the value?


Suppose I have JS code inside a jsp files, such as this:


<%
String test = null;
%>

var test = <%=test%>;

With Tomcat and Websphere the resulting JS will be:


var test = null;

However, in Weblogic it will be:


var test = ;

So with weblogic there is a syntax error.

I know this is fairly easy problem to solve using a condition; somehthing line if test==null print "null" otherwise print test. However, what I am looking for is some kind of server setting that can change this behavior.

I alreay have the code written, so I don't want to search for every place a variable going into JavaScript might be null.

Thanks, Grae


Solution

  • If weblogic tests for null in a JSP expression, you can prevent this by doing:

    <%
    String test = null;
    %>
    
    var test = <%= String.valueOf(test) %>;
    

    This should print var test = null;.