Click here to Skip to main content
15,799,257 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following code & it gives the null pointer exception on line no.62 action=request.getParameter("ACTION")& i'm not getting it
so can somebody help me through this.............

<%@page import="java.util.ArrayList"%>
<%@page import="Ptech.Updation_Deletion"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
    String user_id = (String)session.getAttribute("SID");
    int id = Integer.parseInt(user_id);
    String Name="";
    String UserName="";
    String Password="";
    String From_Date="";
    String To_Date="";
    String Card_ID="";
    String status="";
    String company_name=(String)session.getAttribute("company_name");
    String branch_name=(String)session.getAttribute("Branch_Name");
    Updation_Deletion updel = new Updation_Deletion();
    ArrayList al = new ArrayList();


        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <form action="For Updation_Deletion.jsp" method="post">
        <table border="1" width="200">
            <tr><td>Name:</td><td><input type="text" name="NAME" value="<%=Name%>"/></td></tr>
            <tr><td>UserName:</td><td><input type="text" name="USERNAME" value="<%=UserName%>"/></td></tr>
            <tr><td>Password:</td><td><input type="text" name="PASSWORD" value="<%=Password%>"/></td></tr>
            <tr><td>From_Date:</td><td><input type="text" name="FROM_DATE" value="<%=From_Date%>"/></td></tr>
            <tr><td>To_Date:</td><td><input type="text" name="TO_DATE" value="<%=To_Date%>"/></td></tr>
            <tr><td>Card_ID:</td><td><input type="text" name="CARD_ID" value="<%=Card_ID%>"/></td></tr>
            <tr><td>Status:</td><td><input type="text" name="STATUS" value="<%=status%>"/></td></tr>
            <tr><td>Company_Name:</td><td><input type="text" name="COMPANY_NAME" value="<%=company_name%>"/></td></tr>
            <tr><td>Branch_Name:</td><td><input type="text" name="BRANCH_NAME" value="<%=branch_name%>"/></td></tr>
            <input type="submit" name="ACTION" value="Edit"/>
            <input type="submit" name="ACTION" value="Delete"/>
            <input type="button" name="BACK" value="Back"/>
            String action ="";
      action= request.getParameter("ACTION");
        if (action.equals("Edit")) {
                session.setAttribute("Tr_Flag", "U");
            } else if (action.equals("Delete")) {
                session.setAttribute("Tr_Flag", "D");
            } else {
                session.setAttribute("Tr_Flag", "I");
Updated 21-Aug-13 21:08pm
Thanks7872 22-Aug-13 1:55am    
Am i suppose to find line no.62?
_Asif_ 22-Aug-13 1:58am    
seems like session object has not been appropriately created and initialized and is null therefore raising null pointer exception when you involved setAttribute method. Check why session is null
pasztorpisti 22-Aug-13 5:50am    
Instead of action.equals("Edit") use "Edit".equals(action), this way it isn't a problem if the action variable contains null. In case of comparing with constant strings its always better to call the method of the constant because we know that the constant isn't null and the equals() method deals well with a null parameter.

Looks like you mixed up varaibles in the if clause the line above.
Since you initialize action to an empty string , it is never null. Consequently, checking for action being null - if(!action.equals(null)) - does not make sense. I suspect you wanted to check for request being null.
By the way, where is request initialized?
Share this answer
Both the input field has same name :
<input type="submit" name="ACTION" value="Edit"/>
           <input type="submit" name="ACTION" value="Delete"/>

Try with different name for each input
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900