Reputation: 1673
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
Upvotes: 3
Views: 1693
Reputation: 29139
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.
Upvotes: 2
Reputation: 23373
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;
.
Upvotes: 0