2015-05-04 35 views
1

我是jsp的新手,我遇到了这个运行这个emp.jsp文件的奇怪问题。我知道这是非常基本的,但现在我坚持了两天:P。不能运行一个jsp文件,jstl

<%@ 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> 
+0

http://stackoverflow.com/questions/8045272/javax-servlet-servletexception-java-lang-noclassdeffounderror-javax-servlet-js –

+0

添加这些新瓶后并清理项目现在显示新的错误,找不到标记处理程序类的SQL:查询 –

+0

从JSP中删除JSTL SQL标记,他们永远不会在JSP fiile中,将它们转移到Sevlet,添加数据请求和呈现带有getRequestDispatcher()方法的JSP。 – Shota

回答

0

确保你有你的类路径上的JSTL依赖性:

如果您使用的是Maven,请确保您具有jstl工件的依赖关系:

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

以及我真的不知道如何做现在可以ü请告诉我如何做到这一点我正在使用eclipse –

1

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

+0

javax.servlet.jsp.jstl-1.2.1.jar此文件添加到我的web-inf/lib并正常工作 –

+1

您没有在SQL配置中指定密码,** ** –

+0

是的,我重新启动了我的tomcat服务器8 @pshemo –

0

此例外表明运行时类路径中缺少JSTL API。你似乎只有JSTL impl。我建议删除它并使用jstl-1.2.jar,而不是将API和impl捆绑在一起。

参见:

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

+0

我在阅读后仅使用此文件:) –

+0

您是否在项目中使用Maven? –

+0

它的内部网络inf/lib只,不,我不知道如何使用maven现在 –