• Post Reply Bookmark Topic Watch Topic
  • New Topic

stupid error messge :-)  RSS feed

 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried running the following jsp.
<HTML>
<HEAD><TITLE>My first jsp</TITLE></HEAD>
<BODY>
<%! int angles[] = {0, 30, 45, 75, 90}; %>
<TABLE BORDER ="2" ALIGN ="center">
<TH>Angle</TH><TH>sign of that angle is</TH>
<% for(int i =0; i<5 ; i++) //missing bracket%>
<TR><TD><%=angles[i]%></TD>
<TD><%= Math.sin(Math.toRadians(angles[i]))%>
</TR>
<% }//end for loop %>
</TABLE>
</BODY>
</HTML>
It didn't run as I expected and I realized it was because I missed the opening bracket for the for loop. But I got a error message that said I had a try without a catch. Why would I get an error message that's so misleading? If it's not misleading, how does the message relate to missing a bracket?
 
Phil Hanna
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that a JSP is translated into a servlet, and that scriptlet code gets copied into the _jspService() method of the servlet. The place it gets copied to is inside a try / catch block, so since you had an extra closing bracket, you closed the try block. Take a look at the generated servlet and this will be clearer. If you are using Tomcat, this is in the %TOMCAT%/work directory.
------------------
Phil Hanna
Author of :
JSP: The Complete Reference
Instant Java Servlets
 
vaibhav punekar
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Ronnie,
As rightly said by Phil whole of the JSP scriplet stuff is put inside the "big" try-catch block wherein every Java code is enclosed.So you get such when you do not close the "end brace"correctly.Generally it is suggested that you close the brace at once when the loop is over.In your case try closing it just after your lopp completes.
<TD><%= Math.sin(Math.toRadians(angles[i]))%>
</TR>
<% }//end for loop %>
So instead of this try------
<TD><%= Math.sin(Math.toRadians(angles[i]))}//end loop here%>
</TR>
</table>
If the problem still persists,try putting all your java code in big "try-catch" block.Play with this "}",try varying its position,it ll work.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!