facebook

JSP compile error on "return;" [Closed]

  1. MyEclipse Archived
  2.  > 
  3. Bugs
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #202580 Reply

    ggoldenberg
    Member

    Hello:

    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

    #202581 Reply

    No Operation
    Member

    You 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:” Ignore

    The reason why sloppy servers dont mark that is, they dont use strict compilers.

    NOP

    #202592 Reply

    Riyad Kalla
    Member

    goldenberg,
    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.

    #202722 Reply

    mrzeld
    Member

    i 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.

    #202742 Reply

    No Operation
    Member

    i 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

    #202780 Reply

    mrzeld
    Member

    @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 … 😉
    NOP

    ahhhh. 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.

    #202866 Reply

    No Operation
    Member

    just a tricky trick, since compilers are sometimes not too smart:

    
    if (true) return;
    

    might solve your issue too, but this is a hack.

    NOP

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: JSP compile error on "return;" [Closed]

You must be logged in to post in the forum log in