Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Status 500 - Servlet.init() for servlet Dispatcher threw exception

When I'm trying to run this simple html form:

   <html>
       <head>
        <title>Enter a new Page</title>
       </head>

       <body>

          <div id="editPresPage">
             <form action="editPresPage.do" method="post"> 
            <label>Enter Page ID</label><input type="text" name="page_id"/>
            <label>Enter Header1</label><input type="text" name="h1"/>
            <label>Enter Header2</label><input type="text" name="h2"/>
            <label>Enter Header3</label><input type="text" name="h3"/>
            <label>Enter Header4</label><input type="text" name="h4"/>            
            <label>Enter Page Text</label><input type="text" name="page_text"/>

            <input type="submit" value="Add New Page"/>
         </form>              
          </div>


       </body>
    </html>

I'm getting the error HTTP Status 500 - Servlet.init() for servlet Dispatcher threw exception in my browser.

In my command line window (which opens when I'm running the tomcat's start.batch file) I'm getting the following error:

log4j:WARN No appenders could be found for logger(org.springframework.web.servlet.dispatcherservlet)

My Dispatcher-servlet.xml file:

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">       

        <import resource="/application.xml"/>

        <bean name="/editPresPage.do"
                class="my.pack.webTier.control.EditPresPageController" >
            <property name="page_manager_service" ref="page_manager_service"/>
        </bean> 

       <!--  I also tried using with annotations -->    
        <!-- <context:component-scan base-package="my.pack"/> -->        

</beans>

My web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">

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

    <servlet-mapping>
       <servlet-name>Dispatcher</servlet-name>
       <url-pattern>*.do</url-pattern>
</servlet-mapping>

    <!-- Tomcat configuration -->
    <Context path="/myWebApp" docBase="../tomcat\work\Catalina\localhost\mywebapptomcat\work\Catalina\localhost\mywebapp">
    <Loader
    loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
    </Context>

</web-app>

And thats my controller:

package my.pack.webTier.control;

import my.pack.dataAccessTier.domain.Presentation_page;
import my.pack.serviceTier.services.Page_manager_service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

//@Controller
public class EditPresPageController {

    //@Autowired
    private Page_manager_service page_manager_service;

    public void setPage_manager_service(Page_manager_service page_manager_service) {
        this.page_manager_service = page_manager_service;
    }

    @RequestMapping("/editPresPage")
    public ModelAndView EditPresPage(@RequestParam("page_id") int page_id,
                                     @RequestParam("h1") String h1_value,
                                     @RequestParam("h2") String h2_value,
                                     @RequestParam("h3") String h3_value,
                                     @RequestParam("h4") String h4_value,
                                     @RequestParam("page_text") String page_text)

    {
        Presentation_page new_page=new Presentation_page(page_id,h1_value,h2_value,
                h3_value,h4_value,page_text);

        page_manager_service.create_new_page(new_page);


        return new ModelAndView("/thanks.html");

    }


}

The stacktrace exception:

javax.servlet.ServletException: Servlet.init() for servlet Dispatcher threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    java.lang.Thread.run(Thread.java:722)

I'm working with spring MVC 3.2, eclipse 3.7, springTomcat/7.0.30 and using ANT in my project.

I've searched for an answer for this requirements - and didn't found one.

like image 476
RtmY Avatar asked Feb 19 '13 22:02

RtmY


1 Answers

You map your dispatcher on *.do:

<servlet-mapping>
   <servlet-name>Dispatcher</servlet-name>
   <url-pattern>*.do</url-pattern>
</servlet-mapping>

but your controller is mapped on an url without .do:

@RequestMapping("/editPresPage")

Try changing this to:

@RequestMapping("/editPresPage.do")
like image 65
Dirk Lachowski Avatar answered Nov 12 '22 07:11

Dirk Lachowski