一、JDBC時導包報錯
- 報錯1
<%@ page import="javax.servlet.http.,javax.servlet." %>
The package javax.servlet.http is accessible from more than one module: servlet.api, tomcat.i18n.es, tomcat.i18n.fr, tomcat.i18n.ja
——解決
Tomcat的包路徑要選擇Classpath,否則就不能編譯,導緻找不到Servlet相關的包。
右鍵項目目錄 ----> Properties ----> Java Build Path ----> Libraries ----> ClassPath ---->Add Library ----> Server Runtime ----> Next ----> 選擇tomcat ----> Finish
- 報錯2
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
——解決
安裝JSTL 庫
從Apache的标準标簽庫中下載下傳的二進包(jakarta-taglibs-standard-current.zip)。
- 官方下載下傳位址:http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/
- 本站下載下傳位址:jakarta-taglibs-standard-1.1.2.zip
下載下傳jakarta-taglibs-standard-1.1.2.zip 包并解壓,将jakarta-taglibs-standard-1.1.2/lib/下的兩個jar檔案:standard.jar和jstl.jar檔案拷貝到/WEB-INF/lib/下。
接下來我們在 web.xml 檔案中添加以下配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
<taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
<taglib-location>/WEB-INF/x-rt.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
複制
使用任何庫,你必須在每個JSP檔案中的頭部包含<taglib>标簽。
- 報錯3
頁面500報錯
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
原因:是tomcat找不到MYSQL JAR包的問題
——解決
下載下傳mysql-connector-java-5.1.7-bin.jar并放到tomcat的lib目錄下