0

I'm returning to Spring after a long absence and I'm trying to get a simple web app up and running on Tomcat 6.0 with Hibernate as an ORM.

The error I am getting is:

SEVERE: Servlet.service() for servlet mvc-dispatcher threw exception
java.lang.ClassNotFoundException: org.apache.jsp.WEB_002dINF.view.viewAllEnquiries_jsp

It runs through my controller fine:

@Controller
@ComponentScan("com.intl.cigna.ecommerce.dao")

public class EnquiryController {

    @Autowired
    private EnquiryDao enquiryDao;

    @RequestMapping("/viewAllEnquiries")
    public String getAllEnquiries(Model m) {
        List<Enquiry> enqs = enquiryDao.getAllEnquiries();
        m.addAttribute("SEARCH_ENQUIRIES_RESULTS_KEY", enqs);
        return "viewAllEnquiries";
    }   
}

But for some reason it appears not to compile the jsp. As when I rename or delete the jsp it cannot(obviously) find it.

The web.xml for the dispatcher is:

     <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

I must be missing something obvious...

enkor
  • 7,527
  • 3
  • 31
  • 55
  • Which view resolver configuration are you using? Where do you physically keep your JSP file? – RonK Oct 03 '12 at 14:44
  • I'm using org.springframework.web.servlet.view.InternalResourceViewResolver And the jsp's are in: /WEB-INF/view/ As per the view resolver config. – enkor Oct 03 '12 at 14:46

2 Answers2

2

Just a guess - but it looks like the JSP might not contain valid java code (missing imports and stuff) - so the JSP won't compile to a servlet and you will get the ClassNotFoundException.

Check the catalina.log file to see if there are compilation errors you are missing.

RonK
  • 9,472
  • 8
  • 51
  • 87
  • It appears not to create a log when running via Eclipse WTP, apart from what is in the console output. – enkor Oct 03 '12 at 15:15
  • Did you check under `\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\`? – RonK Oct 03 '12 at 16:25
  • 1
    Also, can you change your JSP to be a simple "hello world" html? – RonK Oct 03 '12 at 16:26
  • ok, a bit of progress. If I remove the jstl libraries(javax.servlet.jsp.jstl and org.glassfish.web) from the pom and make a simple Hello World jsp then it works. It's as if the jstl is causing the error, so suspected a corrupt jar. But removed them from the repository and rebuilt it, but still errors. – enkor Oct 04 '12 at 07:56
  • 1
    Check the war being created - see if the jstl jar is included under `WEB-INF/lib` - my guess is that the construction of the war is the problem and the jar is simply missing from the classpath. – RonK Oct 04 '12 at 08:07
  • Boom! Got it. I was missing the servlet and jsp dependencies, sound obvious but I was building the app from scratch so I would get to understand it better. – enkor Oct 04 '12 at 08:08
1

Make sure you have the all the jstl, servlet and jsp dependencies in your pom/ class path:

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl-api</artifactId>
            <version>1.2</version>
        </dependency>       
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>jstl-impl</artifactId>
            <version>1.2</version>
        </dependency>
enkor
  • 7,527
  • 3
  • 31
  • 55