-1

This code is not real, but is simpler and show the problem

Suppose that I have First File named Base.jsp

<%!
  class Base {
    public String Parm0 = "";
    public String Parm1 = "";

    Base () {
      PrintMessage("Base Created!!");
    }
  }
  javax.servlet.jsp.JspWriter Out;
  void SetJspWriter(javax.servlet.jsp.JspWriter out) {
    Out = out;
  }

  void PrintMessage(String Msg) {
    try {
      Out.print("<P style=\"color:rgb(255,0,0)\">"+Msg+"</P>");
    }
    catch (Exception e) {}
  }
%>

Now I have a Second File that use the base file: Fil0.jsp

<%@ include file="Base.jsp" %>
<%!
  class File0 {
    public Base MyBase;
    File0 () {
      MyBase = new Base();
      PrintMessage("Based Used!!");
    }
  }
%>

Now I have a Third File that use the base file: Fil1.jsp

<%@ include file="Base.jsp" %>
<%@ include file="Fil0.jsp" %>
<%!
  class File1 {
    public Base MyBase;
    public File0 MyFil0;
    File1 () {
      MyBase = new Base();
      MyFil0 = new File0();
      PrintMessage("Based and Fil0 Created!!");
    }
  }
%>
<%
  SetJspWriter(out);
  File1 MyFil1 = new File1();
%>

As you can see... this code will produce messages like:

Duplicate field Fil1_jsp.Out

Duplicate method PrintMessage(String) in type Fil1_jsp

How solve this error Before I need to include Base in two files: File0 and File1. And File1 have Base and File0...

The compiler find two declarations...

1 Answers1

1

Try to insert the line: javax.servlet.jsp.JspWriter Out; only in the last file Fil1.jsp, I think that with the includes you're actually declaring the same object more than once.

Also, you have File0() constructor inside class File1.

Further, since you included Base.jsp in File0.jsp, and then included both Base.jsp and File0.jsp in File1.jsp - you're actually included Base.jsp twice!

If you want to see exactly what's going on, look for the compiled jsp: your jsp files are compiled to .java and can usually be found under tomcat /work folder, in linux it's something like: /usr/local/tomcat/work/Catalina/localhost/_/org/apache/jsp

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129