1

我有 4 个 jsp 文件和 1 个 js 文件:index.jspconnect.jspload1.jspload2.jspfunction.js. 请参阅下面的代码以了解它们之间的关系。

索引.jsp

<%@include file = "load1.jsp" %>
<%@include file = "load2.jsp" %>

连接.jsp

<%!
    public String makeConnection(){
        String str = "connect to database";
        return str;
    }
%>

加载1.jsp

<%@include file = "connect.jsp" %>
<%
    out.print(makeConnection());
%>
<button onclick = "doXHR()">load2</button>

加载2.jsp

<%@include file = "connect.jsp" %>
<%
    out.print(makeConnection());
%>

函数.js

function doXHR(){
    ...
    xmlhttp.open("GET", "load2.jsp", true);
    ...
}

请注意,这些代码不是实际代码,因为我必须使它更简单,以便我可以将它们发布在这里。问题是当我去的时候index.jsp,会有类似的错误makeConnection() is already defined

如果我<%@include file = "connect.jsp" %>从中删除这一行load2.jsp,它会起作用,但如果我点击按钮,它会给出 500 状态代码,它的错误就像cannot find symbol: method makeConnection()

我该如何解决这个问题?谢谢!

4

0 回答 0