- This topic has 6 replies, 4 voices, and was last updated 20 years, 9 months ago by No Operation.
-
AuthorPosts
-
ggoldenbergMemberHello:
The JSP editor reports an error on the following JSP code:
<%
…
response.sendRedirect(“index.jsp”);
return;
%>The (red X) appears on the ending %> line with the error “Unreachable code”. If I remove the “return;” line then the JSP compiles OK. This should not be an error as this JSP compiles and runs fine on my app servers(Tomcat and WebSphere, running independent of Eclipse).
Thanks and keep up the good work!
Glenn– System Setup ——————————-
Operating System and version: Win2Ksp4
Eclipse version: 2.1.2
Eclipse build id: 200311030802
Fresh Eclipse install (y/n): n
If not, was it upgraded to its current version using the update manager? y
Other installed external plugins: y
Number of plugins in the <eclipse>/plugins directory: pde.* – 10
MyEclipse version: 2.7rc2
Eclipse JDK version: 1.4.2_02
Application Server JDK version: n/a
Are there any exceptions in the Eclipse log file? n
No OperationMemberYou MUST ommitt that return, to get well formed code:
<% ... response.sendRedirect("index.jsp"); %>
… and it still works as is should!
Or disable that option in Window->Prefernces->Java->Compiler->Problems
“Unreachable code:” IgnoreThe reason why sloppy servers dont mark that is, they dont use strict compilers.
NOP
Riyad KallaMembergoldenberg,
You should never use return statements in your JSP pages. If you take a look at the generated .java files, there is a lot of wrapping/converting of the JSP page that takes place… putting a stray return statement in will cause the generated code (when it gets compiled to a servlet) to not fully complete its execution of some methods as it will run into your explicit return statement.
mrzeldMemberi actually had a jsp page with a call to response.sendRedirect that continued to execute code on the page after the call. i dont know if it was because it was tomcat 5.0.18 or just the way the jsp is supposed to behave. i had to put a return after that line to get it to work.
to the orginal poster, you might try “if(true) return;” as when you just put “return;” you will get the error message.
No OperationMemberi actually had a jsp page with a call to response.sendRedirect that continued to execute code on the page after the call.
Correct! The code is still executed, but no output is generated.
The possible solutions:
– disable the error/warnings
– rework you application design (recommended)
– … dunno yet … 😉NOP
mrzeldMember@nop wrote:
Correct! The code is still executed, but no output is generated.
The possible solutions:
– disable the error/warnings
– rework you application design (recommended)
– … dunno yet … 😉
NOPahhhh. i guess i didn’t read exacly what the method did then. i designed the page assuming execution would stop. i will have to keep this in mind in the future. thanks.
No OperationMemberjust a tricky trick, since compilers are sometimes not too smart:
if (true) return;
might solve your issue too, but this is a hack.
NOP
-
AuthorPosts