首页 > 代码库 > 在用 <%@include file="date.jsp" %> "date.jsp"老提示出错,错误为: Multiple annotations found at this line: - Duplicate local variable path - Duplicate local variable basePath 该怎么解决呢?

在用 <%@include file="date.jsp" %> "date.jsp"老提示出错,错误为: Multiple annotations found at this line: - Duplicate local variable path - Duplicate local variable basePath 该怎么解决呢?

重复变量

date.jsp文件内部不应该再出现重复的变量定义

也就是<%@include%>是先把文件源代码一模一样的拷贝过来,然后才开始编译
所以如果有相同的变量肯定报错

用了动态的<jsp: include file="top.jsp" />的就正确了

 

因为<%@include%>引进的是代码,把代码包含进来,而新进JSP时,会默认生成

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

 

该指令功能很死板!它是先包含后编译,如果在包含文件中和被包含文件中都有同名变量的定义(例如两文件中都定义了int a = 0;),那就会出现“重复的变量定义 ”的错误,

<jsp: include file="date.jsp" />是先编译后包含,比较高级。它先把包含的文件编译好送到被包航文件中显示。另外,该指令还可以传递参数。

在用 <%@include file="date.jsp" %> "date.jsp"老提示出错,错误为: Multiple annotations found at this line: - Duplicate local variable path - Duplicate local variable basePath 该怎么解决呢?