Question

I'm going through this Spring tutorial online form springsource.org.

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

In Chapter 2, at the end, it has you add a bean to prefix and suffix /WEB-INF/jsp/ and .jsp to responses.

The code so far should basically load index.jsp when you go to localhost:8080/springapp/ which will redirect to localhost:8080/springapp/hello.htm which creates an instance of the HelloController which should in theory send you over to /WEB-INF/jsp/hello.jsp. When I added the prefix/suffix bean and changed all my references to just "hello" instead of the fully pathed jsp file, I started getting the following error:

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

I've tried going back through the samples several times and checking for typo's and I still can't find the problem. Any tips or pointers?

index.jsp (in the root of the 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 (minus the imports and package:

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);
    }
}

My hello.jsp file:

<%@ 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>
Was it helpful?

Solution

It seems like you are missing the JSTL jar here. Try downloading it and place it in your classpath to see if it works: Where can I download JSTL jar

OTHER TIPS

It seems certain required jar(s) are missing from classpath. Make sure you have servlet-api-2.x.jar jsp-api-2.x.jar and jstl-1.x.jar on classpath

Please make sure the jstl.jar file is located in your WEB-INF/lib folder.

As a matter of fact, here is what is stated in the tutorial that you linked. I guess you missed this step:

We will be using the JSP Standard Tag Library (JSTL), so let's start by copying the JSTL files we need to our 'WEB-INF/lib' directory. Copy jstl.jar from the 'spring-framework-2.5/lib/j2ee' directory and standard.jar from the 'spring-framework-2.5/lib/jakarta-taglibs' directory to the 'springapp/war/WEB-INF/lib' directory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top