1

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>
  • http://stackoverflow.com/questions/8045272/javax-servlet-servletexception-java-lang-noclassdeffounderror-javax-servlet-js – Afsun Khammadli May 04 '15 at 13:26
  • after adding those new jars and cleaning the project now new error is showing, the tag handler class was not found for sql:query – Dhruv Parashar May 04 '15 at 14:02
  • Remove JSTL SQL Tags from JSP, they are NEVER ok to be in JSP fiile, transfer them into Sevlet, add data to request and render JSP with getRequestDispatcher() method. – Shota May 05 '15 at 22:09

3 Answers3

1

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

Deepika Rajani
  • 564
  • 5
  • 15
0

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>
Jeroen
  • 3,076
  • 1
  • 17
  • 16
0

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:

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

Community
  • 1
  • 1