473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

if/else statements inside jsps

41
The if else statement inside my jsp is not working, it gives me the following error:

Expand|Select|Wrap|Line Numbers
  1. type Exception report
  2.  
  3. message 
  4.  
  5. description The server encountered an internal error () that prevented it from fulfilling this request.
  6.  
  7. exception 
  8.  
  9. org.apache.jasper.JasperException: Unable to compile class for JSP
  10.  
  11. An error occurred at line: 51 in the jsp file: /website/weather.jsp
  12. Generated servlet error:
  13. The operator > is undefined for the argument type(s) String, int
  14.  
  15.  
  16.     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
  17.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
  18.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  19.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  20.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  21.  
  22.  
  23. root cause 
  24.  
  25. org.apache.jasper.JasperException: Unable to compile class for JSP
  26.  
  27. An error occurred at line: 51 in the jsp file: /website/weather.jsp
  28. Generated servlet error:
  29. The operator > is undefined for the argument type(s) String, int
  30.  
  31.  
  32.     org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
  33.     org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
  34.     org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
  35.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
  36.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
  37.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
  38.     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
  39.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
  40.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  41.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  42.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  43.  
  44.  
  45. note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ page import="java.util.*,java.io.*" %>
  3.  
  4.  
  5.  
  6. <html>
  7. <head>
  8.  
  9. <meta http-equiv="refresh" content="10">
  10.  
  11. <LINK REL="stylesheet" TYPE="text/css" HREF="stylesheet1.css">
  12.  
  13. </head>
  14.  
  15. <body>
  16.  
  17. <hr></hr>
  18.  
  19. <center>
  20.  
  21. <h1> 
  22.  
  23.  Weather Forecast</h1>
  24.  <br>
  25.  
  26.  
  27.  <a href="test.html"> Local Five day forecast </a>
  28.  
  29.  <br><br>
  30.  
  31.  <table border=1   cellpadding=5 cellspacing=0 width="50%">
  32. <tr><th colspan=2>Todays Temperature </th></tr>
  33.  
  34. <tr ><th>Outlook</th> <TD><center><IMG SRC="sunny.gif" ALT="S" BORDER=0 WIDTH=100 HEIGHT=100 ></center></TD></tr>
  35.  
  36.  
  37.  <% 
  38.  
  39.   String tempString;
  40.   BufferedReader dataFile1 = null;
  41.    try {
  42.    //String[] temp = {"Temperature", "Light"};
  43.    int recCount1 = 0;
  44.     FileReader dFile1 = new FileReader("w:/www/DataFile1.txt");
  45.        dataFile1 = new BufferedReader(dFile1);
  46.     tempString = dataFile1.readLine();
  47.     %>
  48.  
  49.  
  50.      <% if (tempString > 30) {  %>
  51.  
  52.    <img src="sunny.gif">
  53.  
  54. <% } else { %>
  55.     <img src="rainy.gif">
  56. <%} %>
  57.  
  58.  
  59.  
  60.     <tr><th>Temperature (Degree Celsius) :</th> <td><%=tempString%></td></tr> 
  61.     <%
  62.  
  63.     while(tempString != null){
  64.  
  65.  
  66. %>
  67.  
  68.  
  69.  
  70.  
  71.  
  72. <%    
  73.  
  74.      recCount1++;
  75.  
  76.      tempString = dataFile1.readLine();
  77.  
  78.     }
  79.    }
  80.    catch (FileNotFoundException e) {
  81.    System.err.println("FileStreamsTest: " + e);
  82.   }
  83.   catch(IOException iOE) {
  84.    iOE.printStackTrace();
  85.   }
  86.   finally {
  87.    dataFile1.close();
  88.   }
  89.  
  90. %>
  91.  
  92. </table>
  93. <br><br><br>
  94.  
  95.  
  96. <table border=1   cellpadding=5 cellspacing=0 width="50%">
  97. <tr><th colspan=2>Todays Light Intensity</th></tr>
  98.  
  99. <tr ><th>Outlook</th> <TD><center><IMG SRC="sunny.gif" ALT="S" BORDER=0 WIDTH=100 HEIGHT=100 ></center></TD></tr>
  100.  
  101.  
  102.  <% 
  103.  
  104.   String valString;
  105.   BufferedReader dataFile = null;
  106.    try {
  107.  
  108.    int recCount = 0;
  109.     FileReader dFile = new FileReader("w:/www/DataFile2.txt");
  110.        dataFile = new BufferedReader(dFile);
  111.     valString = dataFile.readLine();
  112.  
  113.     %>
  114.         <tr><th>Light Intensity (Lux) :</th><td><%=valString%></td> </tr>
  115.     <%
  116.  
  117.     while(valString != null){
  118.  
  119. %>
  120.  
  121.  
  122.  
  123.  
  124. <%    
  125.  
  126.      recCount++;
  127.  
  128.      valString = dataFile.readLine();
  129.  
  130.     }
  131.    }
  132.    catch (FileNotFoundException e) {
  133.    System.err.println("FileStreamsTest: " + e);
  134.   }
  135.   catch(IOException iOE) {
  136.    iOE.printStackTrace();
  137.   }
  138.   finally {
  139.    dataFile.close();
  140.   }
  141.  
  142. %>
  143.  </table>
  144.  
  145.  
  146. <br>
  147. <br>
  148. <br>
  149. <br>
  150. <br>
  151. <br>
  152.  
  153. <hr></hr>
  154.  
  155. </body>
  156. </html>
  157.  
  158.  
  159.  
  160.  
Feb 22 '07 #1
3 3140
abctech
157 100+
You've declared tempString as String and comparing it with an int in 'if'. Perhaps thats why you are getting an error.
Feb 22 '07 #2
r035198x
13,262 8TB
The if else statement inside my jsp is not working, it gives me the following error:

Expand|Select|Wrap|Line Numbers
  1. type Exception report
  2.  
  3. message 
  4.  
  5. description The server encountered an internal error () that prevented it from fulfilling this request.
  6.  
  7. exception 
  8.  
  9. org.apache.jasper.JasperException: Unable to compile class for JSP
  10.  
  11. An error occurred at line: 51 in the jsp file: /website/weather.jsp
  12. Generated servlet error:
  13. The operator > is undefined for the argument type(s) String, int
  14.  
  15.  
  16.     org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
  17.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
  18.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  19.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  20.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  21.  
  22.  
  23. root cause 
  24.  
  25. org.apache.jasper.JasperException: Unable to compile class for JSP
  26.  
  27. An error occurred at line: 51 in the jsp file: /website/weather.jsp
  28. Generated servlet error:
  29. The operator > is undefined for the argument type(s) String, int
  30.  
  31.  
  32.     org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
  33.     org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
  34.     org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
  35.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
  36.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
  37.     org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
  38.     org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
  39.     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303)
  40.     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  41.     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  42.     javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  43.  
  44.  
  45. note The full stack trace of the root cause is available in the Apache Tomcat/5.5.17 logs.
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ page import="java.util.*,java.io.*" %>
  3.  
  4.  
  5.  
  6. <html>
  7. <head>
  8.  
  9. <meta http-equiv="refresh" content="10">
  10.  
  11. <LINK REL="stylesheet" TYPE="text/css" HREF="stylesheet1.css">
  12.  
  13. </head>
  14.  
  15. <body>
  16.  
  17. <hr></hr>
  18.  
  19. <center>
  20.  
  21. <h1> 
  22.  
  23. Weather Forecast</h1>
  24. <br>
  25.  
  26.  
  27. <a href="test.html"> Local Five day forecast </a>
  28.  
  29. <br><br>
  30.  
  31. <table border=1 cellpadding=5 cellspacing=0 width="50%">
  32. <tr><th colspan=2>Todays Temperature </th></tr>
  33.  
  34. <tr ><th>Outlook</th> <TD><center><IMG SRC="sunny.gif" ALT="S" BORDER=0 WIDTH=100 HEIGHT=100 ></center></TD></tr>
  35.  
  36.  
  37. <% 
  38.  
  39. String tempString;
  40. BufferedReader dataFile1 = null;
  41. try {
  42. //String[] temp = {"Temperature", "Light"};
  43. int recCount1 = 0;
  44.     FileReader dFile1 = new FileReader("w:/www/DataFile1.txt");
  45.      dataFile1 = new BufferedReader(dFile1);
  46.     tempString = dataFile1.readLine();
  47.     %>
  48.  
  49.  
  50.      <% if (tempString > 30) { %>
  51.  
  52. <img src="sunny.gif">
  53.  
  54. <% } else { %>
  55. <img src="rainy.gif">
  56. <%} %>
  57.  
  58.  
  59.  
  60.     <tr><th>Temperature (Degree Celsius) :</th> <td><%=tempString%></td></tr> 
  61.     <%
  62.  
  63.     while(tempString != null){
  64.  
  65.  
  66. %>
  67.  
  68.  
  69.  
  70.  
  71.  
  72. <%    
  73.  
  74.      recCount1++;
  75.  
  76.      tempString = dataFile1.readLine();
  77.  
  78.     }
  79. }
  80. catch (FileNotFoundException e) {
  81. System.err.println("FileStreamsTest: " + e);
  82. }
  83. catch(IOException iOE) {
  84. iOE.printStackTrace();
  85. }
  86. finally {
  87. dataFile1.close();
  88. }
  89.  
  90. %>
  91.  
  92. </table>
  93. <br><br><br>
  94.  
  95.  
  96. <table border=1 cellpadding=5 cellspacing=0 width="50%">
  97. <tr><th colspan=2>Todays Light Intensity</th></tr>
  98.  
  99. <tr ><th>Outlook</th> <TD><center><IMG SRC="sunny.gif" ALT="S" BORDER=0 WIDTH=100 HEIGHT=100 ></center></TD></tr>
  100.  
  101.  
  102. <% 
  103.  
  104. String valString;
  105. BufferedReader dataFile = null;
  106. try {
  107.  
  108. int recCount = 0;
  109.     FileReader dFile = new FileReader("w:/www/DataFile2.txt");
  110.      dataFile = new BufferedReader(dFile);
  111.     valString = dataFile.readLine();
  112.  
  113.     %>
  114.         <tr><th>Light Intensity (Lux) :</th><td><%=valString%></td> </tr>
  115.     <%
  116.  
  117.     while(valString != null){
  118.  
  119. %>
  120.  
  121.  
  122.  
  123.  
  124. <%    
  125.  
  126.      recCount++;
  127.  
  128.      valString = dataFile.readLine();
  129.  
  130.     }
  131. }
  132. catch (FileNotFoundException e) {
  133. System.err.println("FileStreamsTest: " + e);
  134. }
  135. catch(IOException iOE) {
  136. iOE.printStackTrace();
  137. }
  138. finally {
  139. dataFile.close();
  140. }
  141.  
  142. %>
  143. </table>
  144.  
  145.  
  146. <br>
  147. <br>
  148. <br>
  149. <br>
  150. <br>
  151. <br>
  152.  
  153. <hr></hr>
  154.  
  155. </body>
  156. </html>
  157.  
  158.  
  159.  
  160.  
Please, do not start many threads for the same problem
Feb 23 '07 #3
dmjpro
2,476 2GB
r u getting complilation or runtime error ....
Feb 24 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ashu | last post by:
Hi All, I wanna know is there any method through which we can use interfaces/Astract classes in JSPs like we implement them in Servlets ? -regards, Ashish
11
by: dmbkiwi | last post by:
I am new to this group, and relatively new to python programming, however, have encountered a problem I just cannot solve through reading the documentation, and searching this group on google. I...
0
by: Alan Sheehan | last post by:
Hi, I am re-engineering a lot of existing Web JSPs and hoping to have each JSP execute a Python script to specify the page contents i.e. a easy way for end users to modify aspects of the pages...
6
by: Bart Nessux | last post by:
Should an if statement have a corresponding else statement? Or, is it OK to have an if statement by itself. For completeness, it seems the two should be together, but from experience I know that a...
5
by: Neil Zanella | last post by:
Hello, Unlike in pre-C99 versions of C where variables can only be defined at the beginning of blocks, C99 allows variables to be defined in arbitrary places inside blocks. However, gcc 3.2.2...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
20
by: Neroku | last post by:
Hello, i would like to know what the serious definition of statements and expressions is: i know an expression are evaluated to a value, i.e: 1 == 2 5+7 foo( 1,2) and a statement is...
5
by: PerlPhi | last post by:
hi,,, while ago i was wondering why do some programmers rarely uses the ternary operator. wherein it is less typing indeed. i believe in the classic virtue of Perl which is laziness. well let me show...
23
by: bearophileHUGS | last post by:
So far in Python I've almost hated the 'else' of the 'for' loops: - I have problems to remember its meaning; - It gives me little problems when I later want to translate Python code to other...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.