473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

I got NumberFormatException in the below code , Please analyze that need do favor

Can i get the values from the same JSP page for further calculation.

Example:
Expand|Select|Wrap|Line Numbers
  1. <html> <form>
  2. Enter ID:<input type="text" name="id"> <%
  3.     String id=request.getParameter("id");
  4.      int no=Integer.ParseInt(id);
  5. :%> </form> </html>
For the above code I got NumberFormatException if it is possible or any other way to achive this in same jsp file.

Thanks in advance
Jul 4 '14 #1
2 1414
rajujrk
107 100+
Use the below Code

Expand|Select|Wrap|Line Numbers
  1.  <html> <form>
  2.     Enter ID:<input type="text" name="id"> <%
  3.         String id=(request.getParameter("id")!=null)?request.getParameter("id"):"0";
  4.          int no=Integer.ParseInt(id);
  5.     :%> </form> </html>

Thanks
Raju
Sep 18 '14 #2
chaarmann
785 Expert 512MB
Integer.ParseInt(id) throws a NumberFormatException if the parameter given does not contain a number. So the code given by Raju does not fix this problem.
For example:

id="Hello";
Integer.ParseInt(id);

So you need to surround your code with a try - catch statement, and in case no number is given you need to do some error handling (e.g. popping up a box with "Please enter a valid number" and focussing on the input field)
Sep 22 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mark Rezansoff | last post by:
I have two examples of populating a treeview with AD information below. example A does exactly what I want, starts at the AD tree, but is really slow to generate. examble B gives more...
4
by: gokcemutlu | last post by:
I want to trace a function while it executes and keep its local variables as states. In trace function all the things work well but after all when I print states, they are all the same. I couldn't...
0
by: shrini | last post by:
hi all..... im not clear of the usage of the following typedef for the function pointer.. can any one help me out, briefing the syntax or usage importance?? code is below.. typedef void...
2
Kosal
by: Kosal | last post by:
Dear All Can you help me to convert as below code to vb.net module Function GF_ListGroupsOfUser(ByVal stUserName As String) As String On Error GoTo err_ListGroupsOfUser Dim...
1
by: sureshl | last post by:
this code works well for the i.e but its not working in firefox . and also i want to do validations only if theatre is selected , but, this is validating for the museum also .code <html> <head>...
3
by: panki1qaz | last post by:
i generated the following code online for a rolling LED text.. but it is hyperlinked to the site from where i generated,, so how to remove it? code:: <embed FlashVars="bt=nullcon Goa 2010 7-8th...
0
by: itsmenarwal | last post by:
HI Everyone.. I am not able to align links,videos,photos etc in right way.Foe example i have aligned sign out on right side page but when i click on any area which falls in the row area(in which...
2
by: Leonidas Savvides | last post by:
HOW detect EOF at below code? what put in place of ( i<3306 ) ??? public mergerTxt() { try { File file = new File( "us-skype.lang" ); // get file name File fileRu = new...
0
by: javedshaikm | last post by:
Data from a XML sheet is converted to php array and I have tried to create a quiz format question with the below code, but it does't work. Not sure how to get it working for multiple questions... ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.