473,407 Members | 2,306 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,407 software developers and data experts.

Jsp: Exception handler issues

108 100+
Greetings,

I'm a newbie to jsp/java so apologies if this request seems trivial.

I have two forms (separate .jsps) which are used to manipulate database records, one adds a record the others update an existing record.

As all fields on the HTML form are text I need to ensure those fields that should be integer values are validated, therefore I include an errorpage (The form action is used to call .jsps needed for the database actions) which acts as a form handler:-
Expand|Select|Wrap|Line Numbers
  1. <%@ page errorPage="EditExceptionHandler.jsp" %>
  2.  
on both the add and edit record .jsps (changing the errorpage accordingly)

Which checks to ensure the sequence field really is an integer, the code for the EditExceptionHandler.jsp is below:-

Expand|Select|Wrap|Line Numbers
  1. <%@ page errorPage="ExceptionHandler.jsp" %>
  2.  
  3. <html>
  4. <%-- Form Handler Code --%>
  5. <a href="wk465682EditFAQ.jsp"> Please try again </a>    
  6. <%
  7.     int faqSequence;
  8.         try{
  9.             faqSequence = Integer.parseInt(request.getParameter("faqSequence"));
  10.             }
  11.     catch (NumberFormatException e)
  12.         { 
  13.             throw new JspException("Please enter a valid integer value !!");
  14.         }
  15.  
  16. %>
  17. </html> 
The code for the ExceptionHandler.jsp is as follows:-

Expand|Select|Wrap|Line Numbers
  1. <%@ page isErrorPage="true" import="java.io.*" %>
  2. <html>
  3. <head>
  4.     <title>Exceptional Event Occurred!</title>
  5.     <style>
  6.     body, p { font-family:Tahoma; font-size:10pt;
  7.         padding-left:30; }
  8.     pre { font-size:8pt; }
  9.     </style>
  10. </head>
  11. <body>
  12. <%-- Exception Handler --%>
  13. <font color="red">
  14. <%= exception.toString() %><br>
  15. </font>
  16. <%
  17. out.println("<!--");
  18. StringWriter sw = new StringWriter();
  19. PrintWriter pw = new PrintWriter(sw);
  20. exception.printStackTrace(pw);
  21. out.print(sw);
  22. sw.close();
  23. pw.close();
  24. out.println("-->");
  25. %>
  26. </body>
  27. </html>
As I have two transactions that require validation for the exact same error how can I combine the functionality?

At the moment when the error is displayed the anchor tag and href isn’t visible (though it is when I add the code to the ExceptionHandler.jsp), I assumed even though it passes the new Exception on it would still display the link.

Then the other issue I have is how can I specify if the error is from XXX.jsp (add or edit .jsp) then return to the same XXX.jsp if I only use one .jsp error handler?

Hope this makes sense.

Thanks
Rob
Mar 26 '08 #1
1 1564
r035198x
13,262 8TB
I suggest that you use Javascripts for the input validations. You can even disable any non-numerical characters from being entered into the fields at all.
It's quicker and thus more user friendly.

To determine which JSP the request is coming from, you can use a hidden parameter in the JSPs with the same name but different values in the different JSPs. Then you simply test for the value of that parameter.
Mar 26 '08 #2

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

Similar topics

9
by: David B | last post by:
Why is it so difficult to report bugs to Microsoft? I have a documented bug and an small test example. I don't really see why I should have to pay to tell them about it... Anyway, the...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
4
by: Frank | last post by:
Hi, I made a handler for unhandled errors. But before that is executed, VB.NET gives me the standard error window. In VB6 there was a setting (errortrapping) about handling errors in the design...
4
by: Rob Richardson | last post by:
Greetings! I am working on an application that targets a Pocket PC running Windows CE and SQL Server CE. Almost all functions in the application use a Try block with a Catch block that looks...
2
by: Nak | last post by:
Hi there, I'm just curious as to something. I have just added an exception handler at the entry point to my application, within the IDE any unhandled exceptions fallback to this and enable me...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
15
by: Mark Lewis | last post by:
I have a weird error trapping problem. When running the IDE everything works fine but not when running in an EXE I get the Unhandled Exception Error message box intead of the one in my Try....Catch...
4
by: mjahabarsadiq | last post by:
HELLO FRIENDS I HAVE ONE JAVA CODE WHICH PARSES AN XML FILE AND PRODUCE A QUERY TO CREATE TABEL IN A DATABASE. BUT I NEED THE CODE TO BE USED IN A JSP PAGE. HOW TO USE THIS PAGE WITH JSP. ...
6
by: Steve | last post by:
Hi All I have a windows forms Application (SAM) in vb.net 2008 using .net framework V2 One and only one customer out of 30 customers is getting errors daily where they have to close and...
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
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
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.