• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in Servlet

 
Kudret Serin
Ranch Hand
Posts: 167
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Why do i get following exception? (The Servlet compiles fine)


type Exception report

message

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

exception

java.lang.NumberFormatException: null
java.lang.Integer.parseInt(Unknown Source)
java.lang.Integer.parseInt(Unknown Source)
com.ex.web.Topla.doPost(Topla.java:15)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


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
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Such as:

[ December 22, 2005: Message edited by: Caine Lai ]
 
Kudret Serin
Ranch Hand
Posts: 167
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic