Forums

This topic is locked

Duplicate database entry redirection error page

Posted 26 Dec 2006 22:49:38
1
has voted
26 Dec 2006 22:49:38 Emma Webster posted:
Hi,

Im trying to set up a system where a user can register for a certain file. I have set up a database where their username and file selection (from a drop down menu) are inserted into a table (made in mysql) upon clicking register. However, I dont want them to be able to register twice for the same thing, i.e. I dont want username + file duplicates. So I have made the username and file fields in my table as primary keys, thus when a none unique entry is made i.e. a duplicate, I want the user to be redirected to an error page telling them their selection is invalid.
Ok, I know you can use the Check New Username feature under server behaviours but the problem is that it only accepts one field to check against - and either choice username or file still redirect me to exception report internal error page - not very user friendly!

Is there a way to get the condition on both username and file via html code or any other means, and redirect to a custom error page to tell the user to try again? Any help would be extremely welcome. Thanks!

Replies

Replied 29 Dec 2006 13:58:46
29 Dec 2006 13:58:46 Emma Webster replied:
I figured it out myself -

Basically, this kind of problem has cropped up in many forums - however the solutions I came across were for VBScript - Im using Java, so they werent helpful. However, what I did find was 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!

Edited by - spiderwebs on 29 Dec 2006 13:59:29

Reply to this topic