我正在通过 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>