NUll POINTER EXCEPTION

NUll POINTER EXCEPTION

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
        float basic = Float.parseFloat(request.getParameter("value1"));
        float da = basic* 0.6f;
        float hra= basic* 0.3f;
        float gross= basic + hra + da;
        request.setAttribute("gr",new  Float(gross));//sharing of data
        RequestDispatcher rd=getServletContext().getRequestDispatcher("/net");
        rd.forward(request,response);

    }

by this block of code i m getting null pointer Exception. can some one please explain what is the problem in this block of code....

View Answers

August 23, 2011 at 5:04 PM

1)grosspay.jsp:

<html>
<form method="get" action="../CalculateSalary">
BASIC: <input type="text" name="value1"><br>
<input type="submit" value="submit"></td></tr>
</table>
</form>
</html>

2)CalculateSalary.java:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

    public class CalculateSalary extends HttpServlet { 
           public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            float basic = Float.parseFloat(request.getParameter("value1")); 
            float da = basic* 0.6f; 
            float hra= basic* 0.3f;
            float gross= basic + hra + da;
            request.setAttribute("gr",new Float(gross));
            RequestDispatcher rd=getServletContext().getRequestDispatcher("/net"); 
            rd.forward(request,response);
         }
         public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
            this.doPost(request, response);
    }
    }

3)Do Servlet mapping in web.xml:

<servlet>
    <servlet-name>CalculateSalary</servlet-name>
        <servlet-class>CalculateSalary</servlet-class>
    </servlet>
<servlet-mapping>
        <servlet-name>CalculateSalary</servlet-name>
        <url-pattern>/CalculateSalary</url-pattern>
    </servlet-mapping>

4)net.java:

import javax.servlet.*; 
import java.io.*;
import javax.servlet.http.*;

public class net extends HttpServlet {
  public void doGet(HttpServletRequest request,   HttpServletResponse response)  throws ServletException, IOException {
  PrintWriter pw = response.getWriter();
response.setContentType("text/html");
PrintWriter out=response.getWriter();
String st=request.getAttribute("gr").toString();
pw.println("Your Salary is: "+st);
}
}

5)Do servlet mapping in web.xml:

<servlet>
        <servlet-name>net</servlet-name>
            <servlet-class>net</servlet-class>
        </servlet>
    <servlet-mapping>
            <servlet-name>net</servlet-name>
            <url-pattern>/net</url-pattern>
        </servlet-mapping>









Related Tutorials/Questions & Answers:
null pointer exception in java
null pointer exception in java  What is null pointer exception in Java and when it occurs? Show it with an example.Thanks!   Java Null Pointer Exception
Httpservletresponse null pointer exception.
Httpservletresponse null pointer exception.  What is Httpservletresponse null pointer exception?   NullPointerException occurs when we try to implement an application without referencing the object and allocating
Advertisements
Null Pointer Exception
Null Pointer Exception  whis is the Null Pointer Exception in java? or define Null Pointer Exception with exp?   NullPointerException occurs, when you try to implement an application without referencing the object
NULL POINTER EXCEPTION
NULL POINTER EXCEPTION    What is the Root cause for Class caste exception in struts frame work .and how 2 handle that 1 please help me
what is a null pointer exception in java
what is a null pointer exception in java  what is a null pointer exception in java
null pointer exception in jsp
null pointer exception in jsp  index.html <html> <...(Exception e) { System.out.println(e); } } %>...); } } catch(Exception e) { out.println(e); } %>
NUll POINTER EXCEPTION
of code i m getting null pointer Exception. can some one please explain what...NUll POINTER EXCEPTION  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
Java null pointer exception
Java null pointer exception  Hi I've made an array of Book objects that I made, the array is called library and it can hold 100 books, but currently...]!=null){ if(strfield.contains(param)){ result+=library[counter
Null pointer exception in hibernate - Hibernate
Null pointer exception in hibernate  Hi i am getting null pointer... is compiled successfully but while running the program i am getting null ponter exception. SessionFactory object is not creating pls give me the solution
Java null pointer exception handling
Java null pointer exception handling   What... program? Is this extends from exception class of Java?   Java null pointer exception handling What is Java NullPointerException? In Java
Null Pointer Exception - Java Beginners
Null Pointer Exception  How Can I Handle NullPoiniterException without using try/catch mechanism
null pointer exception cannot be removed
null pointer exception cannot be removed  class list { public... Exception nothing; public int r; public list() { this(null,null,0); } public list(String e,int i) { this.elem = e; this.next = null
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Getting Null pointer Exception in the jsp page
Getting Null pointer Exception in the jsp page  I have developed this jsp page to store the data in database.While storing the value of check box in database I am getting null pointer exception in the following code
Null Pointer Exception
Null Pointer Exception        Null pointer exceptions are the most common run time ... 3.Point out the reason for null. Understand Null Pointer Exception Suppose we have
Null pointer exception error in Jsp - JSP-Servlet
Null pointer exception error in Jsp  Hi i write a login page. when i validate the login value then the nullpointer exception error is occured. my..." attributes in the input tag So id,userpwd gives null pointer exception
Why the null Pointer exception is comming? - Java Beginners
Why the null Pointer exception is comming?  My code is given below...")); String []oldOne = null; String[]newOne; int i = 0...}; String line; String line1; String[] tokens = null
Null pointer exception error in Jsp - JSP-Servlet
Null pointer exception error in Jsp  Expert:Majid Hi i write a login page. when i validate the login value then the nullpointer exception error..." attributes in the input tag So id,userpwd gives null pointer exception. Thanks
Handle Null Pointer Exception while text file upload
Handle Null Pointer Exception while text file upload  I want the code for handling null pointer exception in jsp page. That is I need an error page for null pointer exception. The cause for null pointer exception is while
when do we get null pointer exception in java
when do we get null pointer exception in java  can anybody explain me abt null pointer exception? like in wt situation do v get NPE? Are these 2 strings same? String str; String str=null
null pointer
null pointer  dear sir , what is mean by null pointer in c
Null pointer execption
Null pointer execption  what is null pointer exception. I am getting the null pointer exception in this line conn= com.mypay.dao.Connection.getConnection(); what is wrong
Null pointer execption
Null pointer execption  what is null pointer exception. I am getting the null pointer exception in this line conn= com.mypay.dao.Connection.getConnection(); what is wrong
Clicking F5 and reentering value throws Null pointer exception
Clicking F5 and reentering value throws Null pointer exception  Hi, My page performs search operation.Normally when i enter a value and click... refresh my page and enter any value it is throwing Null pointer exception.can
check null exception java
check null exception java  check null exception java - How to check the null exception on Java?   The null pointer exception in java occurs... on it. See the example null pointer exception
null pointer exceptions
null pointer exceptions  import java.util.*; public class employee { static int ch; static int emp[]; String name; int id,age..."); } } } Exception in thread "main" java.lang.NullPointerException at employee.insert
null pointer error
null pointer error  Respected sir there is a problem in this code when i add any new record in ms access data base from my code, it gives only null pointer error sir please help me my code are given below compilatation class
null pointer error
null pointer error  Respected sir there is a problem in this code when i add any new record in ms access data base from my code, it gives only null pointer error sir please help me my code are given below compilatation class
Refresh Button returns null point exception when clicked
Refresh Button returns null point exception when clicked  Dear all... button in java. When clicking the button it returns an error "null point exception" Thanks
pointer
pointer  CONSTRTUCT A STRUCTURE FOR EMPLOYEE RECORD THAT CONTAINS A PERSON'S NAME, AGE, EMPLOYEE AND SALARY.WRITE A STATEMENT THAT DECLARES A VARIABLE empInfo and a pointer emPtr of type EMPLOYEE.then use the pointer to display
Null pointer exceptation-Java Servlet web application,Problem connecting with MYSQL database
Null pointer exceptation-Java Servlet web application,Problem connecting... { private static ConnectionPool pool = null; private static DataSource dataSource = null; private ConnectionPool
pointer error java
pointer error java  How to catch null pointer errors in java if the if(value != null) or null
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch..."); JOptionPane.showMessageDialog(null,"connected to database"); // JOptionPane.showMessageDialog(null,"iam here"); stat=con.createStatement(); String ss="select name from
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch..."); JOptionPane.showMessageDialog(null,"connected to database"); // JOptionPane.showMessageDialog(null,"iam here"); stat=con.createStatement(); String ss="select name from
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
show null point Exception """ while trying 2 load a JComboBox"" data is fetch..."); JOptionPane.showMessageDialog(null,"connected to database"); // JOptionPane.showMessageDialog(null,"iam here"); stat=con.createStatement(); String ss="select name from
Pointer a variable
Pointer a variable  hii, Pointer is a variable or not ?   hello,ADS_TO_REPLACE_1 Yes, a pointer is a variable
is there is pointer in java or not??
is there is pointer in java or not??  is there is pointer in java or not plz tell me this with brief?? thank you
exception
exception  Identify the reason for SQLException exception, which..."); ps.executeUpdate(); } catch(Exception e...` ( `id` bigint(255) NOT NULL auto_increment
exception
exception  wHEN RUNTIME EXCEPTION CLASS IS SUB OF EXCEPTION CLASS HOW CAN'T HANDLE UNCHECKED EXCEPTION
java.lang.NumberFormatException: null
java.lang.NumberFormatException: null   I get org.apache.jasper.JasperException: java.lang.NumberFormatException: null exception when i submit the form plz help me regarding this..ADS_TO_REPLACE_1
exception
exception  chek in and check out exception in java   Please visit the following link: Checked and Unchecked Exception
exception
arguments are not equalto two,throw a user defined exception "invalid parameter exception" ,otherwise display the two parameters.   Here is an example... is not equal to two then invalid parameter exception is thrown ,otherwise display the two
exception
exception  what is the use of catch block even though we have predefined exception object
Exception
of NullPointerException in Java program: * If you are calling some method on the null object. * Modifying or accessing the field of a null object. * Trying to get the length of null as if it were an array. * Throwing null value. In the following
exception
exception  example for numberformat exception   Hi Friend, Try the following code:ADS_TO_REPLACE_1 class NumberFormatExceptionEx...); } catch(Exception e){ System.out.println(e
exception
defined checked exception ââ?¬Å?InvalidCharcterFoundExceptionââ?¬Â? and creater a block of codes that will handle the exception
Exception
Exception  whis is the Arithmetic Exception in java? or define Arithmetic Exception with exp?   Arithmetic Exception occurs, when you divide a number by zero. Example public class TryCatch { public static void main
Exception
Exception  public class FooException extends Exception { public..."); } public void calculate() throws FooException, Exception { try { int.... ex.printStackTrace(); System.exit(1); } catch(Exception ex

Ads