Solved

if else and syntax problem

Posted on 2002-07-18
14
171 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
diffSum example 4 53
web services creation SOAP vs REST 5 57
MySqlDump not dumping triggers 1 43
eclipse buid path vs tomcat lib path 10 34
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.

820 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