找到你要的答案

Q:cannot run a jsp file, jstl

Q:不能运行一个JSP文件,JSTL

I am new to jsp and I am having this weird problem of running this emp.jsp file. I know it's very basic but I am stuck for two days now :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>

and error is this

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)

this is my web.xml file as asked by @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>

我是新的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文件要求

<?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>
answer1: 回答1:

Add jstl.jar to your WEB-INF/lib directory.

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

answer2: 回答2:

Make sure you have the jstl dependency on your class path:

If you are using Maven, make sure you have the dependency for jstl artifact:

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

确保你在你的类路径是依赖:

如果你使用Maven,确保你有JSTL伪影的依赖:

<dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
</dependency>
answer3: 回答3:

This exception suggests that the JSTL API is missing in the runtime classpath. You seem to have only the JSTL impl. I suggest to remove it and use jstl-1.2.jar instead which has both the API and impl bundled.

See also:

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

这个异常表明,JSTL API在运行时类路径缺失。你似乎只有JSTL实现。我建议将其使用jstl-1.2.jar相反两者的API和实现捆绑。

参见:

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

java  html  jsp