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:-
-
<%@ page errorPage="EditExceptionHandler.jsp" %>
-
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:-
- <%@ 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>
The code for the ExceptionHandler.jsp is as follows:-
- <%@ 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>
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