1

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>
Kyle
  • 14,036
  • 11
  • 46
  • 61

3 Answers3

2

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

Community
  • 1
  • 1
limc
  • 39,366
  • 20
  • 100
  • 145
  • Thanks, it says in the tutorial to add the jstl.jar and the standard.jar. I must have skipped over the first part of the sentence as I only had the standard.jar... Much appreciated! – Kyle Mar 19 '13 at 01:58
  • No problem... in the future if you see `java.lang.NoClassDefFoundError` exception, chances are you are missing some jars. Just google for the jars and add them to the classpath. – limc Mar 19 '13 at 02:00
1

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

spiritwalker
  • 2,257
  • 14
  • 9
1

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.

Lan
  • 6,470
  • 3
  • 26
  • 37