Solved

if else and syntax problem

Posted on 2002-07-18
14
170 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

770 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