hai everybody,
I tried to compile this servlet but I am getting this error,as shown below.
So please help me out.
code
is://package bonus.controllers;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* This servlet accepts user data and
* returns the bonus in a HTML page.
*/
public class BonusCalculationServlet extends HttpServlet {
/**
* This method will be called by the Servlet Container when
* this servlet is being placed into service.
* @param config - the <CODE>ServletConfig</CODE> object that
* contains configutation information for this servlet.
*/
public void init(ServletConfig config) {
System.out.println("CalculateBonus: init()");
}
/**
* This method calculates bonus based on the given
* input.
* @param multiplier - the multiplier to be used to
* determine the bonus.
* @param bonus - bonus amount to be multiplied.
* @return calculated bonus as a <CODE>double</CODE>.
*/
public double calculateBonus(int multiplier, double bonus) {
// this method simply multiplies the input
// parameters and return the output
double calculatedBonus = (multiplier * bonus);
return calculatedBonus;
}
/**
* This method handles the HTTP GET requests for this servlet.
* It calculates the bonus based on the data passed in the request
* and sends the bonus as a HTML page response.
* @param request - object that contains the request the
* client has made of the servlet.
* @param response - object that contains the response the servlet
* sends to the client.
* @exception java.io.IOException - if an input or output error is
* detected when the servlet handles the GET request.
* @exception ServletException - if the GET request could not be handled.
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// get the multiplier and the social Security number
// information from the request
String inputMultiplier = request.getParameter("multiplier");
String ssn = request.getParameter("ssn");
// convert the data from String form to integer form
Integer multiplierAsInteger = new Integer(inputMultiplier);
int multiplier = multiplierAsInteger.intValue();
// calculate the bonus using the BonusCalculator
double inputBonus = 100.00;
double bonus = this.calculateBonus(multiplier, inputBonus);
// write the response to be displayed
// set the response type
response.setContentType("text/html");
// obtain the writer to write the response
PrintWriter out = response.getWriter();
// write the page title
out.println("<HTML><HEAD><TITLE>");
out.println("Servlet Example - Bonus Calculator");
out.println("</TITLE></HEAD><BODY>");
// write the bonus information
out.println("<H1>Bonus Calculation:</H1>");
out.println("<P>Social Security Number: " + ssn + "<P>");
out.println("<P>Multiplier: " + multiplier + "<P>");
out.println("<P>Bonus Amount: " + bonus + "<P>");
// close the page
out.println("</BODY></HTML>");
// close the writer
out.close();
}
/**
* This method will be called by the Servlet Container when this servlet
* is being taken out of service.
*/
public void destroy() {
System.out.println("BonusCalculationServlet: destroy()");
}
}
The server encountered an internal error () that prevented it from fulfilling this request
java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Integer.java:394)
java.lang.Integer.(Integer.java:567)
BonusCalculationServlet.doGet(BonusCalculationServlet.java:64)
javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
filters.ExampleFilter.doFilter(ExampleFilter.java:149)