1. 程式人生 > >網站開發進階(十六)錯誤提示:Multiple annotations found at this line:- basePath cannot be resolved to a variable

網站開發進階(十六)錯誤提示:Multiple annotations found at this line:- basePath cannot be resolved to a variable

               

錯誤提示:Multiple annotations found at this line: basePath cannot be resolved to a variable

出現以上錯誤,主要是由下面這句引起的:

<base href="<%= basePath %>">

但這句話似乎又沒有任何問題。將這句話刪除問題就得到了解決,而且對原來的網站沒有影響。

經過在網上一番查詢,總結如下:這個錯誤出現的原因是由自己在做jsp檔案引入時引起的,檔案載入合併過程中出現了程式碼載入重複的現象。經過閱讀下面的文件則恍然大悟,原來自己刪了JSP頁面開頭的程式碼,才會出現這樣的問題。將原始碼進行恢復則問題得到解決。

:

JSP<base href="<%=basePath%>">作用

通常在JSP頁面開頭有如下程式碼:

<%  

String path = request.getContextPath();  

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

%>  

 這段程式碼的意思是獲取當前專案的路徑,如:http://localhost:8080/專案名稱。

 在<head></head>中通常有如下程式碼:

 <base href="<%=basePath%>">  

 這是設定基礎路徑的,basePath為變數,簡單的靜態網頁的話你設定比如:<base href="http://www.baidu.com">,那你下面的href屬性就會以你上面設的為基準,如:<a href="http://www.baidu.com/xxx.htm"></a>你現在就只需要寫<a href="xxx.htm"></a>