3

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

GC_
  • 1,673
  • 6
  • 23
  • 39

2 Answers2

2

I don't know if you can control this via server-wide settings, but you can control it war-wide via a setting in the weblogic.xml configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">
    ...
    <wls:jsp-descriptor>
        <wls:print-nulls>true</wls:print-nulls>
    </wls:jsp-descriptor>
</wls:weblogic-web-app>

This needs to go in WebContent/WEB-INF directory next to your web.xml file.

Note that the default is true, so it is odd that you are not seeing nulls. Perhaps this is already set to false elsewhere. Try setting it to true in weblogic.xml as it will override any other setting.

Note that if you have Oracle Enterprise Pack for Eclipse installed for deploying to WLS from Eclipse, you will get a nice editor to help you edit weblogic.xml file. Look for this setting under JSP -> Output Options in the content outline.

Konstantin Komissarchik
  • 28,879
  • 6
  • 61
  • 61
0

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;.

rsp
  • 23,135
  • 6
  • 55
  • 69
  • 1
    I am looking for a weblogic setting. I know you can use various Java tricks to get around it. I just don't to search everywhere in the code to find every place I <%=...%> might have null in it. – GC_ Apr 05 '11 at 16:47
  • It seem like a lot of code changes, just to support at server. – GC_ Apr 05 '11 at 16:47
  • This solution works, I could never get any of other things to work. – GC_ May 04 '11 at 22:13