Hi,
I am using RequestDispatcher to forward data from servlet to JSP.
[CODE]
try{
HttpSession session=request.getSession(true);
session.setAttribute("LoginMessage",loginMessage);
RequestDispatcher rd=request.getRequestDispatcher("../LoginMessage.jsp");
rd.forward(request,response);
}catch(Exception e){
System.out.println("error2 in doGet "+e);
e.printStackTrace();
out.println("error2 in doGet");
[/CODE]
I am working in JBoss 3.2.1, When I run the servlet in browser I get this error:
[CODE]
21:02:02,013 INFO [STDOUT] error2 in doGet java.lang.NullPointerException
21:02:02,013 ERROR [STDERR] java.lang.NullPointerException
21:02:02,013 ERROR [STDERR] at au.com.tusc.servlet.MyServlet.doPost(MyServlet.java:69)
21:02:02,013 ERROR [STDERR] at au.com.tusc.servlet.MyServlet.doGet(MyServlet.java:80)
21:02:02,013 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
21:02:02,013 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
21:02:02,013 ERROR [STDERR] at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)
21:02:02,013 ERROR [STDERR] at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)
21:02:02,013 ERROR [STDERR] at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)
21:02:02,013 ERROR [STDERR] at org.mortbay.http.HttpContext.handle(HttpContext.java:1714)
21:02:02,013 ERROR [STDERR] at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:507)
21:02:02,013 ERROR [STDERR] at org.mortbay.http.HttpContext.handle(HttpContext.java:1664)
21:02:02,013 ERROR [STDERR] at org.mortbay.http.HttpServer.service(HttpServer.java:863)
21:02:02,013 ERROR [STDERR] at org.jboss.jetty.Jetty.service(Jetty.java:460)
21:02:02,013 ERROR [STDERR] at org.mortbay.http.HttpConnection.service(HttpConnection.java:775)
21:02:02,013 ERROR [STDERR] at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)
21:02:02,013 ERROR [STDERR] at org.mortbay.http.HttpConnection.handle(HttpConnection.java:792)
21:02:02,013 ERROR [STDERR] at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)
21:02:02,013 ERROR [STDERR] at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)
21:02:02,013 ERROR [STDERR] at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)
[/CODE]
What may be the problem? why is rd null? Please help.
Thanks,
Abhishek
-
Using RequestDispatcher, NullPointerException (2 messages)
- Posted by: Abhishek Asthana
- Posted on: March 03 2005 00:22 EST
Threaded Messages (2)
- Using RequestDispatcher, NullPointerException by Jeroen Kampen on March 03 2005 12:10 EST
- Using RequestDispatcher, NullPointerException by Amit Kumar on March 03 2005 17:41 EST
-
Using RequestDispatcher, NullPointerException[ Go to top ]
- Posted by: Jeroen Kampen
- Posted on: March 03 2005 12:10 EST
- in response to Abhishek Asthana
You sure it's rd that is null? (Check the line numbers in the stack trace against your source code or debug your doGet method).
Note that null does not mean your jsp doesn't exist at the location specified. According to the Servlet API, getRequestDispatcher only returns null if the ServletContext cannot create a RequestDispatcher, which should not happen under normal conditions, I think. -
Using RequestDispatcher, NullPointerException[ Go to top ]
- Posted by: Amit Kumar
- Posted on: March 03 2005 17:41 EST
- in response to Jeroen Kampen
Yeap!! Your rd is null. Check your jsp path again. It’s not reachable.