一、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目录下