TCLUG Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

weird bug



here is a weird bug that I cannot figure out in a servlet i am writing.
The servlet takes in req.paramaters from an HTML form, all fields are
taken in as strings, and I out put the values of each onto a browser
just to see what their values are and one of them comes back as NULL
when nothing is entered into it and I hit submit, and when I enter
anything into it it throws a NULLPOINTER exception. Hhere is some
snippets of code:

HTML form :

<table border="0" background=""><font face="arial" size="2">
<TR><TD width="115">Client ID:</td><td width="250"><input type="text"
size="10" maxlength="100" name="clientID"></td></tr>
<TR><TD width="115">Company name:</td><td width="250"><input type="text"
size="30" maxlength="100" name="coName"></td></tr>


Servlet Code:
            // client table data members
        private String clientid;
        private String comp = "";  // or I have used no intialization



       // get form information
    clientid = req.getParameter("clientID");
    comp = req.getParameter("coName");

    //output values
        output.println(clientid);
         output.println(comp);



Null pointer exception: ( i was using doPost, but it was suggested to
use service to me. I am using a post method from my HTML form, would
doPost be better than a plain old service method? I get this error
either way)

Error: 500

Internal Servlet Error:

java.lang.NullPointerException
        at SetupServlet.service(SetupServlet.java, Compiled Code)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
        at
com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155)
        at
com.sun.web.core.InvokerServlet.service(InvokerServlet.java:168)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
        at
com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155)
        at com.sun.web.core.Context.handleRequest(Context.java:414)
        at
com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:139)