# Logical Operators

zuzsso
48

Hi there. I have a problem with Java scripts.
I have this piece of code:

<zscript language="Java">
void aMethod() Source Code
{//Method starts
//Declarations--------------------------
String logVal;
String pasVal;
//Sentences-----------------------------
logVal="a Value";
pasVal= "otherValue";
//Let check if values are the same
if (logVal.equals(pasVal) & (logVal!=null))
{//If Block starts
//Entry Condition: Two values match and logVal is not null
}//If Block endss
else
{//Else block starts
//Entry Condition: Two values don't macth or logVal is null
alert ("You aren't logged in, try again");
}//Else block endss
}//Method endss
</zscript>


I built the application and load the page onto the browser. Tomcat reply with an error message: "The entity name must inmediately follow the '&' in the entity reference"

The error is caused by the use of "&" operator in "if" sentence.
However, if I used the "|" operator, rewriting like this, the page works fine:
if (!logVal.equals(pasVal) | (!logVal!=null)))


The question is: What is the AND operator? That's "&" in Java, but it doesn't works in the script

delete retag edit

## 2 Replies

mjablonski
1284 3 5
http://www.jease.org/

Hi,

this is a problem with escaping the ampersand, which has a special meaning in XML. You'll have to use a CDATA-Section like the following:

<zscript><![CDATA[
... here you can use & as you like...
]]></zscript>

I would recommend to always use a CDATA-Section within ZScript.

HTH, Maik

zuzsso
48

Thankyou very much mjablonski. I'll try as you recommend. I tried the && operator and works fine. Regards!!!
PD: It worked because I separated the code from the view, into a page called check.zul. This page was referenced using the src attribute for the zscript tag

[hide preview]