Solved

if else and syntax problem

Posted on 2002-07-18
14
168 Views
Last Modified: 2010-03-31
The following was working then I had to add another condition and now it is not working if I add what is blocked out

- what i wanted to add was
refURL.endsWith("esccServlet") ||  (refURI.beginsWith("pbc2"))

from
refURL.endsWith("esccServlet") )
What is not right??

<%
boolean  display = false ;
String refURL = request.getHeader("referer");
//String refURI = request.getRequestURI("uri");
if ( (new Integer(passedCalculatedElecSerDay)).intValue()>0 )
{
display = true;
}
if ( (new Integer(passedCalculatedElecSerYear)).intValue()>0 )
{
display = true;
}
if  ( display == true && refURL != null &&
 //refURL.endsWith("esccServlet") ||  (refURI.beginsWith("pbc2"))
  //(refURI.beginsWith("pbc2"))
    refURL.endsWith("esccServlet"))
  //(refURI.endsWith("pbc2"))
{
%>    
0
Comment
Question by:schroom
  • 7
  • 4
  • 3
14 Comments
 
LVL 9

Expert Comment

by:Ovi
ID: 7162031
if  ( display == true && refURL != null &&  (refURL.endsWith("esccServlet") ||  (refURI.beginsWith("pbc2")))
0
 
LVL 35

Expert Comment

by:girionis
ID: 7162035
 You have statements without a OR and/or AND checking. You cannot do it. And you have more parenthesis than actual needed. (refURI.beginsWith("pbc2")) can be written as refURI.beginsWith("pbc2").

  I am not sure what exactly you are tryign to look for but the above coudl be written as:

if  (  (display == true && refURL != null &&
      refURL.endsWith("esccServlet")) ||  
     (refURI.beginsWith("pbc2") &&
     refURI.beginsWith("pbc2") &&
     refURL.endsWith("esccServlet") &&
     refURI.endsWith("pbc2"))
     )

  Change the OR/AND checking and parenthesis accordingly to obtain whatever result.

  Hope it helps.
0
 

Author Comment

by:schroom
ID: 7162040
this is the error I get with the below:
expected. if ( display == true && refURL != null && (refURL.endsWith("esccServlet") || (refURI.startsWith("pbc2"))) ^ /u/ws03/as01/jit/default_host/pbcdev/_10calculator_2D_e_jsp_0.java:649: 'else' without 'if'. } else { ^ 2 errors

<%
boolean  display = false ;
String refURL = request.getHeader("referer");
String refURI = request.getRequestURI();
if ( (new Integer(passedCalculatedElecSerDay)).intValue()>0 )
{
display = true;
}
if ( (new Integer(passedCalculatedElecSerYear)).intValue()>0 )
{
display = true;
}

  if  ( display == true && refURL != null &&  (refURL.endsWith("esccServlet") ||  (refURI.startsWith("pbc2")))
{
%>    
0
 
LVL 35

Expert Comment

by:girionis
ID: 7162090
 Make sure you have a matching closing bracket somewhere.

  And put everythign inside parenthesis, just in case:

 if  ( (display == true) && (refURL != null) &&  (refURL.endsWith("esccServlet") ||  (refURI.startsWith("pbc2")))
0
 
LVL 35

Accepted Solution

by:
girionis earned 100 total points
ID: 7162100
After more careful consideration this:

 if  ( display == true && refURL != null &&  (refURL.endsWith("esccServlet") ||  (refURI.startsWith("pbc2")))


  should be:

  if  ( display == true && refURL != null &&  (refURL.endsWith("esccServlet") ||  refURI.startsWith("pbc2")))

  Hope it helps.
0
 

Author Comment

by:schroom
ID: 7162112
Getting closer this is my errro now.
??
ANy more suggestions thanks for your help

Unable to compile class for JSP "/15calculator-e.jsp" /u/ws03/as01/jit/default_host/pbcdev/_15calculator_2D_e_jsp_0.java:630: Undefined variable or class name: refURI if ( display == true && refURL != null && (refURL.endsWith("esccServlet") || refURI.startsWith("pbc2"))) ^ Note: /u/ws03/as01/jit/default_host/pbcdev/_15calculator_2D_e_jsp_0.java uses or overrides a deprecated API. Recompile with "-deprecation" for details. 1 error, 1 warning
0
 

Author Comment

by:schroom
ID: 7162121
Getting closer this is my errro now.
??
ANy more suggestions thanks for your help

Unable to compile class for JSP "/15calculator-e.jsp" /u/ws03/as01/jit/default_host/pbcdev/_15calculator_2D_e_jsp_0.java:630: Undefined variable or class name: refURI if ( display == true && refURL != null && (refURL.endsWith("esccServlet") || refURI.startsWith("pbc2"))) ^ Note: /u/ws03/as01/jit/default_host/pbcdev/_15calculator_2D_e_jsp_0.java uses or overrides a deprecated API. Recompile with "-deprecation" for details. 1 error, 1 warning
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:schroom
ID: 7162128
it is good now thanks
I had to put back in
String refURI = request.getRequestURI();

<%
boolean  display = false ;
String refURL = request.getHeader("referer");
String refURI = request.getRequestURI();
if ( (new Integer(passedCalculatedElecSerDay)).intValue()>0 )
{
display = true;
}
if ( (new Integer(passedCalculatedElecSerYear)).intValue()>0 )
{
display = true;
}
if  ( display == true && refURL != null &&  (refURL.endsWith("esccServlet") ||  refURI.startsWith("pbc2")))
{
%>    
0
 
LVL 35

Expert Comment

by:girionis
ID: 7162147
 Thank you schroom I am glad I helped as well but I think Ovi is worth the points since he was the one who suggested the solution. ]:-)
0
 
LVL 9

Expert Comment

by:Ovi
ID: 7162300
if  ( display == true && refURL != null &&  (refURL.endsWith("esccServlet") ||  (refURI.beginsWith("pbc2")))
0
 

Author Comment

by:schroom
ID: 7162312
Sorry Ovi, there seemed to be a lag or something in the posts
0
 

Author Comment

by:schroom
ID: 7162313
Sorry Ovi, there seemed to be a lag or something in the posts
0
 

Author Comment

by:schroom
ID: 7162338
Sorry Ovi, there seemed to be a lag or something in the posts
0
 
LVL 9

Expert Comment

by:Ovi
ID: 7162465
I don't uderstand what you meen. My comment was the first posted to your question ... But any way, is not a problem that you have graded the points to someone else. Glad to see you happy with your problem resolved ... -:)
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now