JSP 使用<%@include%>报Duplicate local variable path 错误 解决方法

错误提示:
Multiple annotations found at this line:
- Duplicate local variable path
- Duplicate local variable 
basePath

重复变量,
因为<%@include%>引进的是代码,把代码包含进来,而新进JSP时,会默认生成
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<base href="<%=basePath%>">
这二句代码,所以用<%@include%>引进页面是就报重复变量 basePath 
解决方法,把要引进页面这句去掉就行.
 
 
 

对于静态包含,<%@include%>,中包含的文件,只是简单的嵌入到主文件中,就是在jsp页面转化成Servlet时才嵌入到主文件中,因为运行的结果是只生成了一个Servlet。

而对于动态包含<jsp:incude>如果被包含文件是动态的,那么就会生成两个Servlet,也就是被包含文件也要经过jsp引擎编译执行生成一个Servlet,两个Servlet通过request和reponse进行通信。如果被包含的文件是静态的,那么这种情况和<%@include>就很相似,只生成了一个Servlet,但是他们之间没有进行简单的嵌入,而依然是通过request和reponse进行的通信。

原文地址:https://www.cnblogs.com/lyb0103/p/7857654.html