我正在浏览来自 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>
最佳答案
看来您在这里缺少 JSTL jar。尝试下载它并将它放在类路径中以查看它是否有效:Where can I download JSTL jar
关于java - 未找到 Spring Web 服务类异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15490123/