【问题标题】:Spring Web Services Class Not Found ExceptionSpring Web Services 类未找到异常
【发布时间】:2013-03-07 13:47:15
【问题描述】:

我正在通过 springsource.org 在线阅读这个 Spring 教程。

http://static.springsource.org/docs/Spring-MVC-step-by-step/part2.html

在第 2 章的最后,它让您在响应中添加一个 bean 前缀和后缀 /WEB-INF/jsp/.jsp

到目前为止,代码基本上应该在您转到 localhost:8080/springapp/ 时加载 index.jsp,这将重定向到 localhost:8080/springapp/hello.htm,它创建一个 HelloController 的实例,理论上应该将您发送过来到 /WEB-INF/jsp/hello.jsp。当我添加前缀/后缀 bean 并将所有引用更改为“hello”而不是完全路径的 jsp 文件时,我开始收到以下错误:

message Handler processing failed; nested exception is 
java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/fmt/LocalizationContext

我已尝试多次查看示例并检查错字,但我仍然找不到问题。有什么提示或指示吗?

index.jsp(在 webapp 的根目录中:

<%@ include file="/WEB-INF/jsp/include.jsp" %>

<%-- Redirected because we can't set the welcome page to a virtual URL. --%>
<c:redirect url="/hello.htm" />

HelloController.java(减去导入和包:

public class HelloController implements Controller {

protected final Log logger = LogFactory.getLog(getClass());

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

        String now = (new Date()).toString();
        logger.info("Returning hello view with " + now);

        return new ModelAndView("hello", "now", now);
    }
}

我的 hello.jsp 文件:

<%@ include file="/WEB-INF/jsp/include.jsp" %>

<!DOCTYPE html>
<html>
    <head>
        <title>Hello :: Spring Application</title>
    </head>
    <body>
        <h1>Hello - Spring Application</h1>
        <p>Greetings, it is now <c:out value="${now}" /></p>
    </body>
</html>

【问题讨论】:

    标签: java spring jsp spring-ws spring-tool-suite


    【解决方案1】:

    您似乎在这里缺少 JSTL jar。尝试下载它并将它放在你的类路径中,看看它是否有效:Where can I download JSTL jar

    【讨论】:

    • 谢谢,教程中说要添加 jstl.jar 和 standard.jar。我必须跳过句子的第一部分,因为我只有standard.jar...非常感谢!
    • 没问题...将来如果您看到java.lang.NoClassDefFoundError 异常,您可能会丢失一些罐子。只需用谷歌搜索 jars 并将它们添加到类路径中。
    【解决方案2】:

    类路径中似乎缺少某些必需的 jar。 确保在类路径上有 servlet-api-2.x.jar jsp-api-2.x.jarjstl-1.x.jar

    【讨论】:

      【解决方案3】:

      请确保jstl.jar 文件位于您的WEB-INF/lib 文件夹中。

      事实上,这是您链接的教程中所述的内容。我猜你错过了这一步:

      我们将使用 JSP 标准标签库 (JSTL),所以让我们开始吧 通过将我们需要的 JSTL 文件复制到我们的“WEB-INF/lib”目录中。复制 'spring-framework-2.5/lib/j2ee' 目录中的 jstl.jar 和 来自“spring-framework-2.5/lib/jakarta-taglibs”的standard.jar 目录到'springapp/war/WEB-INF/lib'目录。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-13
        • 1970-01-01
        • 1970-01-01
        • 2012-02-28
        • 1970-01-01
        相关资源
        最近更新 更多