1. 程式人生 > >javax.servlet.ServletException cannot be resolved to a type錯誤解決方法

javax.servlet.ServletException cannot be resolved to a type錯誤解決方法

在頁面中使用全域性路徑時${pageContext.request.contextPath}出現javax.servlet.ServletException cannot be resolved to a type錯誤,解決方法如下:

這個錯誤主要是因為缺少jsp-api.jar servlet-api.jar這兩個Jar包。

第一種解決方法:

直接把 Tomcat7.0 lib目錄中的 jsp-api.jar 新增  Build path 中。

第二種解決方法:
使用 Maven jsp-api.jar   servlet-api.jar 一起新增到專案中,
需要注意的是使用 Maven 加入的

jar  <scope>test</scope> 需要設定為test
jar包不能夠隨工程一起釋出,預設沒有配置 scope 表示隨專案一起釋出。
因為專案最終要釋出到Tomcat下執行,而Tomcat自身就具有這兩個jar包,如果隨
專案釋出的話專案提供的2jar會和Tomcat自身的2Jar衝突,會丟擲 NullPintException

或者用maven:

1. <dependency>  

2.     <groupId>javax.servlet.jsp</groupId>  

3.     <artifactId>jsp-api</artifactId>

  

4.     <version>2.1</version>  

5.     <scope>provided</scope>  

6. </dependency> 

最後說明一點有時候架包不可以直接複製到lib下面,而是通過外部jar包引用。

專案 右鍵->Properties->Libraries->Add External JARS-
選擇 外部的jsp-api.jar(tomcat6的lib目錄下有)。


相關推薦

javax.servlet.ServletException cannot be resolved to a type錯誤解決方法

在頁面中使用全域性路徑時${pageContext.request.contextPath}出現javax.servlet.ServletException cannot be resolved to a type錯誤,解決方法如下:這個錯誤主要是因為缺少jsp-api.ja

使用Maven建立Web專案後,jsp引入靜態檔案提示報錯。JSP 報錯:javax.servlet.ServletException cannot be resolved to a type

使用Maven建立Web專案後,jsp引入靜態檔案提示報錯。 錯誤提示:javax.servlet.ServletException cannot be resolved to a type 錯誤如下圖: 解決方案: 1. 在Maven的pom檔案中引發如下依賴即可: &

xxx cannot be resolved to a type 錯誤解決方法

xxx cannot be resolved to a type引言    eclipse新匯入的專案經常可以看到“XX cannot be resolved to a type”的報錯資訊。本文將做以簡單總結。 正文    (1)jdk不匹配(或不存在)     專案指定的

Jsp頁面:Mulyiple annotations found at this line:-javax.servlet.jsp cannot be resolved to a type

JSP頁面中報錯,在網上查查之後得出方案。 解決方案: 右鍵專案-build path 選擇configure build path 點選Add External JARs.. 然後選中tomcat伺服器下bin目錄裡面的jsp-api.jar、s

HttpServlet cannot be resolved to a type錯誤解決方案

HttpServlet cannot be resolved to a type報錯 原因解釋: jdk 裡不包括servlet-api.jar 這個包,此包在Tomcat 中存在 專案名–> 右鍵 –>Property–> 選擇 Java Build Pa

MyEclipse/Eclipse中enum cannot be resolved to a type 錯誤解決

概要: enum型別是在jdk1.5之後出現的,所以在java中要使用enum型別需要jdk1.5以上 場景: 在MyEclipse中有時候我們機器上明明裝的就是jdk1.6,配置的也是jdk6,可就

InterceptorRef cannot be resolved to a type 錯誤解決辦法

       今天在通過註解寫Interceptor時,在使用@InterceptorRef時,一直出現InterceptorRef cannot be resolved to a type。按經驗,

eclipse中" cannot be resolved to a type"的解決辦法

博主今天在敲程式碼的時候發現報了" cannot be resolved to a type"這個錯誤,在網上一搜才知道解決方案,現在分享給大家:    (1)jdk不匹配(或不存在)      專案指定的jdk為“jdk1.6.0_18”,而當前eclipse使用的是“j

org.apache.jasper.JasperException: Unable to compile class for JSP: List cannot be resolved to a type 錯誤

org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 163 in the jsp file: /touch/management/pe

Android Eclipse匯入原始碼時對自己新增的class檔案提示"XXX cannot be resolved to a type"的解決辦法

Eclipse匯入原始碼時對自己新增的class檔案提示"XXX cannot be resolved to a type"錯誤提示,且在Eclipse中點選該class物件時無法跳轉到該類,解決辦法

jsp 頁面 javax.servlet.jsp.JspException cannot be resolved to a type 異常

not pro ima png post version 圖片 exce com <dependencies><dependency><groupId>javax.servlet</groupId><artifactId

javax.servlet.jsp.PageContext cannot be resolved to a type

not in cti 報錯 clas div stack contex question pen jsp項目中報錯: javax.servlet.jsp.PageContext cannot be resolved to a type stack overflow上找的解決

解決javax.servlet.jsp.JspException cannot be resolved to a type

pex jsp lib javax art jar let article 存在 java開發工具 在導入新項目後出現 javax.servlet.jsp.JspException cannot be resolved to a type錯誤信息: 解決方案:   看看項目

解決javax.servlet.jsp.JspException cannot be resolved to a type異常問題

使用eclipse-juno新建的maven專案,使用過程中無任何問題,但是換了eclipse-luna版本後,匯入同樣的maven專案,則報javax.servlet.jsp.JspException cannot be resolved to a type錯誤;這可能是新版本eclipse的bu

eclipse,myeclipse匯入工程報:javax.servlet.jsp.JspException cannot be resolved to a type

今天從別的地方匯入工程的時候,發現匯入進來出現javax.servlet.jsp.JspException cannot be resolved to a type異常資訊,但是在工程匯出來的時候並沒有錯,原因是在工程中少了jsp-api.jar 包。 解決辦法:在工程中新增jsp-api.jar包,tom

HttpServletRequest cannot be resolved to a type The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

HttpServletRequest cannot be resolved to a type The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 解決辦法: 這是因為專案中缺少兩個

javax.servlet.jsp.JspException cannot be resolved to a type

javax.servlet.jsp.PageContext cannot be resolved to a type javax.servlet.jsp.JspException cannot be resolved to a type 剛開始學jsp,servlet時

javax.servlet.jsp.PageContext cannot be resolved to a type報錯解決方法

專案-->右鍵Properties-->選擇Java Build Path-->選擇Libraries-->Add External JARs-->選擇../tomcat/lib/下的jsp-api.jar和servlet-api.jar兩個ja

關於 javax.servlet.jsp.PageContext cannot be resolved to a type

問題:當從一個專案中拷貝jsp檔案到另一個專案中出現報錯:javax.servlet.jsp.PageContext cannot be resolved to a type 解決方法一:新增依賴(推

javax.servlet.jsp.PageContext cannot be resolved to a type相關報錯

開發十年,就只剩下這套架構體系了! >>>