1

I want to display selected Row data from jsp page to another jsp page.For taht i am passing selected row data to servlet using the hidden id. But I am getting the null pointer exception while sending data from jsp to Servlet.

please find my below code:

In jsp code:

   <tr > 
        <form action="DisplayData" method="get">
          <TD ><%=item.getAPPLICATIONID()%></TD>
          <TD><%=item.getAPPLICATIONNAME()%></TD>
          <input type="hidden" id="sid" name="sid" value=<%=item.getAPPLICATIONID() %>>

            <TD><input type="submit" value="Submit" ></TD>
         <%

}

Servlet Code:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    DBConnection db=new DBConnection();
    HttpSession hs = request.getSession();
    Integer pid =(Integer) request.getAttribute("sid");
    List<ApplicationList> dbean=db.getAllaplicationsList(pid);
    hs.setAttribute("detbean",dbean);
    response.sendRedirect("Output.jsp");

}

I am getting null pointer Exception in Servlet page. The value is pid is showing null.Could you please suggest me how can resolve this issue.

Muskan
  • 1
  • 10
  • did `<%=item.getAPPLICATIONID()%>` is displaying any value. – udaybhaskar Dec 07 '16 at 12:53
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – vanje Dec 07 '16 at 13:15
  • 1
    use `request.getParameter("sid")` instead of `request.getAttribute("sid")` P.S. you have missed the quotes on hidden field value, it should be `` – drgPP Dec 07 '16 at 13:28
  • Yeah..i am able to get the response. but i have passed applicationName in the value . If i am trying to pass ApplicationID in the hidden value, in servlet i am not able to convert int to string in getparameter .. could you please suggest me how to pass the int value to servlet in getParameter – Muskan Dec 07 '16 at 17:51
  • actually, i want to pass the int id to getParameter to meet my proper functionality . but in getParameter only String is acceptable. So, could you please suggest me how to pass int value in getParameter. or any other way ..Thank you in advance – Muskan Dec 07 '16 at 18:01
  • My issue is resolved now. Thank you all for your help . – Muskan Dec 07 '16 at 18:25
  • My question i am using the submit button to select the row in the displayed table in jsp. But i do not want to display submit button in table. I want when i move the cursor to particular row , it should send value to servelet .could you please suggest me as soon. because it is very urgent – Muskan Dec 07 '16 at 18:31

0 Answers0