Thankyou for your reply! I will certainly have a look at AJAX.
However, I found a way to create a custom error message, as opposed to the http 500 error page. This isnt the absolute solution to redirecting to a custom error page specific to a duplicate entry error, but is an error page for whatever error crops up, and so overrides the default http 500 page!
All you need to do, if you are using Java, is to insert errorPage="yourcustomerrorpage.jsp" into:
<%@page language="java" import="java.sql.*"%> (top of the code)
So that you get...
<%@page language="java" import="java.sql.*" errorPage="yourcustomerrorpage.jsp"%>
Obviously, yourcustomerrorpage, is a page you made yourself!
This worked for me, hope it helps other people too!