tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael E. Locasto" <loca...@cs.columbia.edu>
Subject Re: nullpointer (on forward) in tomcat (both 331 & 332)
Date Sat, 03 Aug 2002 13:28:44 GMT
Jeff,

The Javadocs for ServletContext.getRequestDispatcher( String pathname ):

"The pathname must begin with a "/" and is interpreted as relative to the
current context root. Use getContext to obtain a RequestDispatcher for
resources in foreign contexts. This method returns null if the
ServletContext cannot return a RequestDispatcher."

Also, add a test here:

>   try {rd = sc.getRequestDispatcher(nextPage);
              if( rd==null )
                System.out.println( "Rd is null." );
    }
>   catch (NullPointerException np) {
>      System.out.println("********************* NullPointerException on
> getRequestDispatcher ********************");
>      np.printStackTrace();
>    }

Hope that helps...

Regards,
Michael


----- Original Message -----
From: "Jeff Boring" <jwboring@tampabay.rr.com>
To: <tomcat-user@jakarta.apache.org>
Sent: Saturday, August 03, 2002 9:01 AM
Subject: nullpointer (on forward) in tomcat (both 331 & 332)


> The following servlet code throws nullpointer (on forward) in tomcat
> (both 3.3.1 & 3.3.2). Any ideas where to start looking?
>
> Jeff W. Boring
> jwboring@tampabay.rr.com
>
> ------------------------------ code -----------------------------
> public void forwardToNextPage(String nextPage, HttpServletRequest req,
> HttpServletResponse res) throws IOException, ServletException {
>
>   System.out.println("*****************************************");
>   System.out.println("************ REQ ----->" + req.toString() );
>   System.out.println("*****************************************");
>   System.out.println("*****************************************");
>   System.out.println("************ RES ----->" + res.toString() );
>   System.out.println("*****************************************");
>
>   ServletContext sc = null;
>   RequestDispatcher rd = null;
>
>   try {sc = getServletContext();}
>   catch (NullPointerException np) {
>     System.out.println("********************* NullPointerException on
> getServletContext ********************");
>     np.printStackTrace();
>   }
>   try {rd = sc.getRequestDispatcher(nextPage); }
>   catch (NullPointerException np) {
>      System.out.println("********************* NullPointerException on
> getRequestDispatcher ********************");
>      np.printStackTrace();
>    }
>    try {rd.forward(req, res);}
>    catch (NullPointerException np) {
>      System.out.println("********************* NullPointerException on
> forward ********************");
>      np.printStackTrace();
>    }
>
> ----------------------- console --------------------------------------
>
> ********************* NullPointerException on forward
> ********************
> java.lang.NullPointerException
>         at
> com.ibm.eadtraining.servlet.EADTrainingController.forwardToNextPage(E
> ADTrainingController.java:89)
>         at
> com.ibm.eadtraining.servlet.EADTrainingController.submitLogin(EADTrai
> ningController.java:212)
>         at
> com.ibm.eadtraining.servlet.EADTrainingController.doPost(EADTrainingC
> ontroller.java:46)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java)
>         at
> org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java
> :570)
>         at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
>         at org.apache.tomcat.core.Handler.service(Handler.java:235)
>         at
> org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:4
> 81)
>         at
> org.apache.tomcat.core.ContextManager.internalService(ContextManager.
> java:917)
>         at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:833
> )
>         at
> org.apache.tomcat.modules.server.Http10Interceptor.processConnection(
> Http10Interceptor.java:176)
>         at
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
> :508)
>         at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
> ool.java:533)
>         at java.lang.Thread.run(Thread.java:479)
>
>
> --
> To unsubscribe, e-mail:
<mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:tomcat-user-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message