JSP使用 報Duplicate local variable basepath 錯誤的解決辦法

當出現此錯誤時重複變量:

引入的jsp頁面會自動加入<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

和頁面中的變量重複,去掉引入頁面的此代碼就行。

引自:http://www.cnblogs.com/wangjing1982/p/3267979.html

錯誤提示:

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

解決方法,把要引進頁面這句去掉就行,

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章