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
- <%@ page errorPage="EditExceptionHandler.jsp" %>
Which checks to ensure the sequence field really is an integer, the code for the EditExceptionHandler.jsp is below:-
Expand|Select|Wrap|Line Numbers
- <%@ page errorPage="ExceptionHandler.jsp" %>
- <html>
- <%-- Form Handler Code --%>
- <a href="wk465682EditFAQ.jsp"> Please try again </a>
- <%
- int faqSequence;
- try{
- faqSequence = Integer.parseInt(request.getParameter("faqSequence"));
- }
- catch (NumberFormatException e)
- {
- throw new JspException("Please enter a valid integer value !!");
- }
- %>
- </html>
Expand|Select|Wrap|Line Numbers
- <%@ page isErrorPage="true" import="java.io.*" %>
- <html>
- <head>
- <title>Exceptional Event Occurred!</title>
- <style>
- body, p { font-family:Tahoma; font-size:10pt;
- padding-left:30; }
- pre { font-size:8pt; }
- </style>
- </head>
- <body>
- <%-- Exception Handler --%>
- <font color="red">
- <%= exception.toString() %><br>
- </font>
- <%
- out.println("<!--");
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- exception.printStackTrace(pw);
- out.print(sw);
- sw.close();
- pw.close();
- out.println("-->");
- %>
- </body>
- </html>
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