无法运行JSP文件JSTL



我是JSP的新手,并且我有运行此emp.jsp文件的奇怪问题。我知道这是非常基本的,但我现在被困了两天:p。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Page</title>
</head>
<body>
    <sql:setDataSource var="connection" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/tutorials" user="root" password="" />
    <sql:query var="result" dataSource="${connection }">
        select * from registration
    </sql:query>
    <table border="0" width="75%">
        <tr>
            <th>id</th>
            <th>name</th>
            <th>password</th>
            <th>usertype</th>
        </tr>
        <c:forEach var="col" items="${result.rows }">
        <tr>
            <td><c:out value="${col.id}"></c:out></td>
            <td><c:out value="${col.name}"></c:out></td>
            <td><c:out value="${col.password}"></c:out></td>
            <td><c:out value="${col.usertype}"></c:out></td>
        </tr>
        </c:forEach>
    </table>
</body>
</html>

和错误是此

javax.servlet.ServletException: java.lang.NoClassDefFoundError:   javax/servlet/jsp/jstl/sql/SQLExecutionTag
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

这是我的web.xml文件,如@rajani

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>Tutorials</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

添加 jstl.jar 到您的WEB-INF/lib目录。

确保您对类路径具有JSTL依赖性:

如果您使用的是Maven,请确保您具有JSTL伪像的依赖性:

<dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
</dependency>

此异常表明在运行时类Path中缺少JSTL API。您似乎只有JSTL的含义。我建议将其删除并使用jstl-1.2.jar,既有api又有bunded。

另请参见:

https://stackoverflow.com/tags/jstl/info

最新更新