I'm getting a null pointer exception pointing to the line containing
dispatcher.forward(request,response);
Any suggestions as to where i have gone wrong. it wud be of gr8 help...
thanks in advance:)

ArrayList empList =EmployeeDao.getEmpDetail();//this is defined already
   
      request.setAttribute("empList",empList);
   
      RequestDispatcher disp = request.getRequestDispatcher("/myPage.jsp")
      
      disp.forward(request,response);
ArrayList employeeList=null;
   
      ArrayList employeeList=(ArrayList)request.getAttribute("empList");
   
     
   
     
      if(!employeeList.isEmpty())
   
      {
   
      for(int i=0;i<employeeList.size();i++)
   
      {
   
      %>
  
       
  
      <tr>
  
      <Td><%=employeeList.get(0)%></Td>
  
      <Td><%=newslist.get(1)%></Td>
  
      </tr>
  
      <%
  
      }
  
      }
  
      %>

Recommended Answers

All 7 Replies

Are you sure that ArrayList empList =EmployeeDao.getEmpDetail();//this is defined already doesn't return null value?

i too had the same doubt..
so just after ArrayList empList =EmployeeDao.getEmpDetail();
i inserted

for(int i=0;i<al.size();i++){
System.Out.Println((Employee)al.get(i)).getName());
System.Out.Println((Employee)al.get(i)).getEmpID());
}

i got desiered o/p there name n the ID was displayed
thers smthing else causing the trouble not able to figure out

Can you provide exact error you getting? I do not see anything wrong with above code...

HTTP Status 500
java.lang.NullPointerException
EmployeeInfo.doPost(EmployeeInfo.java:8)
and line 8 refers to -

disp.forward(request,response);

OK, I will need to see whole servlet if you can post it

Problem Solved. A silly mistake request was supposed to go to a file named mypage.jsp(original file with the content) in my webapps and the request was going to myPage.jsp which had nothing in it . Thank you so much for your time and suggestions.:)

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class NetServlet extends HttpServlet
{
    public void doGet(HttpServletRequest request43,HttpServletResponse response43)throws IOException
    {
        float gross=(Float)request43.getAttribute("dpa");
        float deductions=gross*0.06f;
        float net=gross-deductions;
        response43.setContentType("text/html");
        PrintWriter out=response43.getWriter();
        out.println("<html>");
        out.println("<body bgcolor=skyblue>");
        out.println("<h1>take home salary is Rs:"+net+"<h1>");
        out.println("<body>");
        out.println("</html>");
        out.close();


    }
}

i

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.