facebook

Duplicate local variable

  1. MyEclipse IDE
  2.  > 
  3. Installation, Configuration & Updates
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #212387 Reply

    Donald Scott
    Participant

    Hello

    I am having a problem with a jsp. Actually there are 2 issues that I think are related to one problem:
    1) There is a compile error “Duplicate local variable sc”.
    First, I tried renaming the variable to be sure there were no collisions with other includes, this didn’t work.
    Then, I changed from using a jsp file as the include jsp to using a jspf.

    An interesting think about this compile error, if I make ANY change in the editor and save/build it, then the error disappears until I close the editor and reopen it.

    2) When I deploy and run under Tomcat, I get the error
    sc is already defined in _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)

    I am running MyEclipse 3.0 build 200406192000 and Tomcat 5.0.27 (I have tried 4.1.30 as well)

    Here is a snippet from the jsp:

    <%@include file=”pageSetup.jspf” %>
    <%@include file=”htmlHeader.jsp” %>
    <%
    Boolean changeFlag = (Boolean)session.getAttribute(sc.CHANGE_FLAG_ATTR);
    boolean isChange = changeFlag != null;

    //This is used for the locationDrill.jsp & equipmentDrill.jsp
    request.setAttribute(sc.FIX_LOC_ATTR, new Boolean(false));
    request.setAttribute(sc.FIX_EQUIP_ATTR, new Boolean(true));

    Here is the pageSetup.jspf:

    <%@page
    import=”java.util.*,vtam.manager.*,vtam.dataobject.*,vtam.servlet.*”
    %>
    <%
    // use for short reference to (static) shared constants
    SharedConstants sc = null;

    // use for short reference to (static) helper methods
    BaseServlet bs = null;

    // messages about database operations
    String errMsg = (String)request.getAttribute(sc2.ERR_MSG_ATTR);
    String updtMsg = (String)request.getAttribute(sc2.UPDT_MSG_ATTR);

    // use this for formatting dates
    java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(sc2.DF_DISP_PTRN);

    // most pages will make use of at least one iterator
    Iterator iter;

    // make sure they are logged in
    if(!request.getRequestURI().endsWith(sc2.LOGIN_PAGE))
    {
    if(session.getAttribute(sc2.USER_ATTR) == null) {
    response.sendRedirect(sc2.LOGIN_PAGE);
    return;
    }
    }
    %>

    #212394 Reply

    Riyad Kalla
    Member

    I wonder of the jasper 2 compiler is already generating a variable named “sc” in the page when it converts it to a servlet… can you try and comment our your line “SharedConsants sc = null” and instead have a line “System.out.println(sc);” and deploy it and see if it prints anything out?

    If Tomcat is giving you a problem here too I’m not sure that this is a ME issue… you may just want to rename it to “sharedConstants” or something like that?

    #212407 Reply

    Donald Scott
    Participant

    I tried renaming it to sc_ and sc2, sc3. I don’t think it is an actual collision.
    The ME issue is the compile error “Duplicate local variable sc”. I am able to get the jsp to compile by editing the file and saving/building it. I then deploy it to Tomcat and when I access the page, I get a compiler error from Tomcat saying that the sc variable is already defined. I can’t imagine they are not the same error.

    Here is something else that is interesting. My application has 2 jsps prior to the one with the error. All three jsps include the pageSetup.jsp, but only the third page has the problem.

    #212433 Reply

    Riyad Kalla
    Member

    Do you define a variable “sc” any other place in your project? Maybe in that pageSetup.jsp page? Try renaming that and see if the problem goes away.

    #212543 Reply

    Donald Scott
    Participant

    The variable sc is defined only in the pageSetup.jsp.
    I renamed it again to sc2 (I have tried renaming it to sc2, sc3, sc_). This time the MyEclipse error “Duplicate Local Variable” went away, so I reverted to using the sc variable. The MyEclipse error did not return, however, the same error in Tomcat exists where it says
    “sc is already defined in _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)”

    I’m confused as to why the MyEclipse error would magically stop appearing.
    I’m quite sure that these 2 errors are related and any additional help would be appreciated.

    #212566 Reply

    Riyad Kalla
    Member

    don,
    I have tried this locally many different ways and cannot reproduce the problem. I would suggest you search your entire project for the string ” sc ” and see where you are defining that variable, I bet its more place than one.

    #212572 Reply

    Donald Scott
    Participant

    I found the problem.
    My jsp was including the pageSetup.jsp and then later in the file it was including another jsp that was including the pageSetup.jsp. I imported the code into WSAD and it identified the two import statements. Maybe MyEclipse should do something like this as well.

    Thanks

    #212578 Reply

    Riyad Kalla
    Member

    That is a good suggestion, I will send it along.

    I’m glad you got it figured out.

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: Duplicate local variable

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