473,698 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

if/else statements inside jsps

41 New Member
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 3161
abctech
157 New Member
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 MVP
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 Top Contributor
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
1555
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
97194
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 have written a theme in python for the superkaramba theme engine on kde (see http://netdragon.sourceforge.net - if you are a kde/linux user, it is a great visual applet engine). I have uploaded it to www.kdelook.org for others to download and...
0
1294
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 without deep Java know-how. I have proven the above by creating an interpreter in each page and simply executing a script file.
6
2501
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 if statement by itself works just fine. Below is an example: if x >=0: DO SOMETHING Would it be better, or perhaps more complete, written like this:
5
10150
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 seems to reveal that there are still places where this is illegal. For instance, consider the following code snippet. int main(void) { int i = 0;
32
6118
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 understand Finally runs whether an error was caught or not, I haven't found a use for finally yet.
20
2012
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 executed: break;
5
3562
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 you something first before i go to my delimma. codes as follows using Mrs. If Else: #!perl/bin/perl use strict; print "Are you sure you want to quit ('yes' or any key for 'no'): "; chomp($_ = <STDIN>);
23
2772
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 languages (and you always have to translate long-lived code). - I have used it only once, so far. So so far I'd liked to see it removed from Python 3.0. But then this article:
0
8675
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8862
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2331
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.