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
解決方法,把要引進頁面這句去掉就行,
不想刪掉,因爲要用到“path”這個變量,用來指定CSS路徑,怎麼辦????????????
.搞定了,有2個方法
重命名path和basePath變量,,要不不引用path,直接用request.getContextPath();