【问题标题】:Can't get JSTL to work with Spring MVC无法让 JSTL 与 Spring MVC 一起使用
【发布时间】:2016-03-03 01:05:19
【问题描述】:

我似乎无法让 JSTL 与我当前的安装一起工作。我最近开始摆弄 Spring MVC,一边尝试一边学习。在我开始使用 JSTL 之前感觉很棒,但我似乎无法正确使用它。

我得到的错误是

org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.jsp.HelloWorld_jsp

我的 HelloWorld.jsp 文件:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Posts</title>
</head>
<body>
<c:foreach var="post" items="${listPosts}" varStatus="status">
    ${status.index + 1} ${post.title}<br />
</c:foreach>
</body>
</html>

如果你需要它们,我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>groupId</groupId>
    <artifactId>HelloWorld</artifactId>
    <version>1.0-SNAPSHOT</version>

</project>

还有 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

我已经正确设置了 CLASSPATH 环境变量(到 tomcat 的 lib 文件夹),我尝试将 jstl-1.2.jar 放在 WEB-INF/lib 文件夹中,并尝试在 pom.xml 中多次声明依赖项(做我用谷歌搜索的事情,不确定它们有多正确)。到目前为止没有任何效果。

【问题讨论】:

  • 好吧,无论如何,您都需要将 jstl 依赖项放在那里。可能有一些版本混淆的问题
  • 对于初学者,当遇到您不理解的异常时,请始终包含您可以在服务器日志中找到的 整个 堆栈跟踪。对于了解异常的中间人来说,堆栈跟踪的最底层根本原因就足够了,因为它本身就是代表整个答案的部分。

标签: java spring maven spring-mvc jstl


【解决方案1】:

问题很可能是您的 pom.xml 中缺少依赖项。

建议:

请发回你找到的东西!

【讨论】:

    猜你喜欢
    • 2015-07-06
    • 2015-12-09
    • 1970-01-01
    • 2011-10-16
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    相关资源
    最近更新 更多