File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Exception in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Exception in Servlet" Watch "Exception in Servlet" New topic

Exception in Servlet

Kudret Serin
Ranch Hand

Joined: Aug 02, 2005
Posts: 167

Hi all,
Why do i get following exception? (The Servlet compiles fine)

type Exception report


description The server encountered an internal error () that prevented it from fulfilling this request.


java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.11 logs.

And the servlet is:
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

If there is no sayi1 parameter in the request, then request.getParameter("sayi1") returns null. Since converting null to an int is meaningless, Integer.parseInt(sayi1) throws that exception.

You should put some logic in that code that does things differently if there is no sayi1 (or no sayi2) parameter in the request.
Caine Lai

Joined: Sep 21, 2005
Posts: 15
Such as:

[ December 22, 2005: Message edited by: Caine Lai ]

Online collaboration made simple: <a href="" target="_blank" rel="nofollow"></a>
Kudret Serin
Ranch Hand

Joined: Aug 02, 2005
Posts: 167

i made a typo in html file so that the servlet can not get the parameters from the request.
Dummy mistake:

Number 1: <input type="text name="sayi1"><br>
Number 2: <input type="text name="sayi2">

Thanks for the replies.
I agree. Here's the link:
subject: Exception in Servlet
It's not a secret anymore!