Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -



This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1 game2d


    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 57 posts

Posted 16 April 2013 - 04:04 AM

i have a form with two fields. one is string and other int. than if user hit submit button than i am checking to see if there are errors. 1st error is if string is empty. 2nd error is if int field is empty. this is where i need help. i dont know how to check if int field is empty or not.
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
     <form method="post" action="index.jsp">
what's your name?<br/>
<input type="text" name="usernameField"/><br/>
what's your aga?<br/>
<input type="text" name="ageField" /><br/>
<input type="submit" name="submit" />
if (request.getParameter("submit") != null) {
String username = request.getParameter("usernameField");
int number1 = Integer.parseInt(request.getParameter("ageField"));
//check errors
out.print("Error enter name");
else if(number1 == 0)  //help here
out.print("Error enter age");
out.print("answer" + number1);
already tried these things but didnt worked:
int number1 = Integer.parseInt(request.getParameter("ageField"));
  if(request.getParameter("ageField") == null)
   if(number = null)

#2 Petros


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 117 posts

Posted 16 April 2013 - 04:33 AM

Have u try this  Integer number1 = Integer.valueof(request.getParameter("ageField")); 

Java Java Doooooo!!!

#3 wim DC

wim DC


  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts

Posted 16 April 2013 - 05:37 AM

First process your ageField as a String, you can check null and size then. And only after those checks parse it into an int.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download