Dear Java Pros,

I am getting the following exception when I try to extend the struts Actionservlet. The reason I need to extend the ActionServlet is that I need to perform some initializations for my web application. Could you help me with this? Also attached is my ControllerServlet code and the action mapping from struts-config.xml

Regards,

Sunil

/testInit

StandardWrapperValve[action]: Servlet.service() for servlet action threw exception

java.lang.NullPointerException

java.lang.NullPointerException

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1557)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510)

at com.testpilot.ControllerServlet.doPost(ControllerServlet.java:31)

at com.testpilot.ControllerServlet.doGet(ControllerServlet.java:40)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)

at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)

at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)

at java.lang.Thread.run(Thread.java:484)


ControllerServlet code

package com.testpilot;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.*;

public class ControllerServlet extends ActionServlet {

    public void init(ServletConfig config) throws ServletException {
//some initialization code will go here
    }


    public void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
      // This tells the Controller servlet what action is requested by the user
      String requestString = processPath(request);

      if(!requestString.equals("/testInit")) {
          //process the request by the respective actions
      }
      else{
        System.out.println(requestString);
        super.doPost(request, response);
      }
      requestString = null; // setting the request string to null
   }


   public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
          throws ServletException, IOException {
        doPost(request, response);
    }


    /** destroy method for clean up */
    public void destroy() {
    }
}


struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>

  <!-- ========== Form Bean Definitions =================================== -->
  <form-beans>
    <!-- Default form bean -->
    <form-bean name="defaultForm" type="org.apache.struts.action.ActionFormBean" />
    <!-- Logon form bean -->
    <form-bean name="loginForm" type="com.testpilot.LoginForm"/>
  </form-beans>

  <!-- ========== Global Forward Definitions ============================== -->
  <global-forwards type="org.apache.struts.action.ActionForward">
     <forward name="login" path="/login.jsp" />
     <forward name="success" path="/mainMenu.jsp" />
  </global-forwards>

  <action-mappings>
    <action path="/testInit" name="defaultForm" scope="request" type="com.testpilot.TestPilotInitAction">
        <forward name="success" path="/login.jsp" />
    </action>
  
  </action-mappings>
</struts-config>