Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

if else and syntax problem

Posted on 2002-07-18
14
Medium Priority
?
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 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 …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

670 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