473,399 Members | 3,401 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,399 software developers and data experts.

Problem in code

madhoriya22
252 100+
Hi,
Here is the code snippet in which I have problem. When this part throws exception, request is sent to ErrorPage.jsp. Now the problem is, after forwarding the request to errorPage, the program should halt at this place and this value should not go in database...It takes hoursSpent value as 0......how should I halt flow at this point
Expand|Select|Wrap|Line Numbers
  1. double hoursSpent = 0;
  2.         try {
  3.             hoursSpent = Double.parseDouble(request.getParameter("hoursSpentInput"));
  4.         }catch(NumberFormatException nfe) {
  5.             System.out.println("not a number"+nfe);
  6.             request.setAttribute("Message","Enter a number in 'Hours Spent'");
  7.             request.getRequestDispatcher("ErrorPage.jsp").forward(request,response);
  8.         }
  9. .......//some code here
  10.  
Jul 23 '07 #1
4 1843
JosAH
11,448 Expert 8TB
Hi,
Here is the code snippet in which I have problem. When this part throws exception, request is sent to ErrorPage.jsp. Now the problem is, after forwarding the request to errorPage, the program should halt at this place and this value should not go in database...It takes hoursSpent value as 0......how should I halt flow at this point
Expand|Select|Wrap|Line Numbers
  1. double hoursSpent = 0;
  2.         try {
  3.             hoursSpent = Double.parseDouble(request.getParameter("hoursSpentInput"));
  4.         }catch(NumberFormatException nfe) {
  5.             System.out.println("not a number"+nfe);
  6.             request.setAttribute("Message","Enter a number in 'Hours Spent'");
  7.             request.getRequestDispatcher("ErrorPage.jsp").forward(request,response);
  8.         }
  9. .......//some code here
  10.  
After the catch clause has executed control flow continues at your
'// some code here' where you most likely fiddle with your database again.
Don't do that, simply return at the end of your catch clause.

kind regards,

Jos
Jul 23 '07 #2
madhoriya22
252 100+
After the catch clause has executed control flow continues at your
'// some code here' where you most likely fiddle with your database again.
Don't do that, simply return at the end of your catch clause.

kind regards,

Jos
Thanks Jos......Its working......Can you plz tell me how make code colourful while putting it in code tags :)
Jul 23 '07 #3
JosAH
11,448 Expert 8TB
Thanks Jos......Its working......Can you plz tell me how make code colourful while putting it in code tags :)
Those colour are pre-set; given the kind of code tag, the colours differ; I don't
know the reason behind this all; here are a few examples

Expand|Select|Wrap|Line Numbers
  1. for (int i= 0; i < n; i++) System.out.println("Hello world");
  2.  
Expand|Select|Wrap|Line Numbers
  1. for (int i= 0; i < n; i++) printf("Hello world\n");
  2.  
Expand|Select|Wrap|Line Numbers
  1. for (int i= 0; i < n; i++) cout << "Hello world" << eol;
  2.  
I really have no idea why those colours should be different; and please don't ask
me about those line numbers either; I'm innocent ;-)

kind regards,

Jos
Jul 23 '07 #4
madhoriya22
252 100+
Those colour are pre-set; given the kind of code tag, the colours differ; I don't
know the reason behind this all; here are a few examples

Expand|Select|Wrap|Line Numbers
  1. for (int i= 0; i < n; i++) System.out.println("Hello world");
  2.  
Expand|Select|Wrap|Line Numbers
  1. for (int i= 0; i < n; i++) printf("Hello world\n");
  2.  
Expand|Select|Wrap|Line Numbers
  1. for (int i= 0; i < n; i++) cout << "Hello world" << eol;
  2.  


I really have no idea why those colours should be different; and please don't ask
me about those line numbers either; I'm innocent ;-)

kind regards,

Jos
whatever u told is OK...........sorry if u find my question too silly.......
Thanks :)
Jul 23 '07 #5

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

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
7
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two...
6
by: harry | last post by:
Hi, I have a program that runs on multiple client pc's. Occasionally one or more of those pc's use VPN to connect to another corporate network. When using VPN they need to set proxy server in...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
2
by: Praveen K | last post by:
I have a problem in communicating between the C# and the Excel Interop objects. The problem is something as described below. I use Microsoft Office-XP PIA dll’s as these dll’s were been...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.