我有4个jsp文件和1个js文件:index.jsp
,connect.jsp
,load1.jsp
,load2.jsp
和function.js
。请参阅以下代码以了解它们之间的关系。
index.jsp的
<%@include file = "load1.jsp" %>
<%@include file = "load2.jsp" %>
connect.jsp
<%!
public String makeConnection(){
String str = "connect to database";
return str;
}
%>
load1.jsp
<%@include file = "connect.jsp" %>
<%
out.print(makeConnection());
%>
<button onclick = "doXHR()">load2</button>
load2.jsp
<%@include file = "connect.jsp" %>
<%
out.print(makeConnection());
%>
function.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()
。登记/>
我怎么解决这个问题?谢谢!