http exception error stack

Hi people,

Im trying to handle an exception in my servlet by res.sendRedirect to another page..but it is not redirecting to the page i want, instead its going to a HTTP Staus 500 error page detailing the full stack trace..can someone tell me what might be wrong here, ive attached code..

Many thanks
oggiemc
import java.io.*;
import java.lang.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

import javax.servlet.http.HttpServletResponse;

import oracle.jdbc.driver.*;

public class Manager2 { 
	
	Connection con = null;
	Statement stmt = null;
	PreparedStatement pstmt;
	ResultSet rs = null;
	String JDBCUrl = "jdbc:xxxxxxxxxxxxxx";
	String username = "xxxx";
	String password = "xxxx";


		
	public void Register(String Username, String Password, 
			String Surname, String Firstname, String Email, String Phone, 
			    PrintWriter out, HttpServletResponse res) throws IOException
	{
              String username = Username;
              String password = Password;
              String surname = Surname;
              String firstname = Firstname;
              String email = Email;
              String phone = Phone;
		
		try
		{
		
		pstmt = con.prepareStatement("INSERT INTO FMC_EMPLOYEE " +
				"(USERID,PASSWORD,SURNAME,FIRSTNAME,EMAIL,PHONE)VALUES(?,?,?,?,?,?)");
		  pstmt.clearParameters();       
		  pstmt.setString(1, username);
		  pstmt.setString(2, password);
		  pstmt.setString(3, surname);
		  pstmt.setString(4, firstname);
		  pstmt.setString(5, email);
		  pstmt.setString(6, phone);
		  pstmt.executeUpdate();
			                                                                                 	   		                                                                                   
		  pstmt.close();

		}
		catch (Exception e) {
		res.sendRedirect("/Fergal/EmployeeRegister.html");
 
	    }
		
	}
}

Open in new window

oggiemcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
do the redirect in your servlet by have the register method throw an exeption and catch it in your servlet

0
oggiemcAuthor Commented:
Thanks for reply objects,

Not to sure what you mean..Is that not what i have done?

public void Register(String Username, String Password,
            String Surname, String Firstname, String Email, String Phone,
                                     PrintWriter out, HttpServletResponse res) throws IOException
...........
...........
catch (Exception e) {
                res.sendRedirect("/Fergal/EmployeeRegister.html");
0
objectsCommented:
no you are redirecting from your Register class.
I am saying you should be doing the redirection in your servlet class
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

oggiemcAuthor Commented:
so the register method throws the exception, but the servlet that callled the method catches it??
how do i do that? do i put the catch statement after the method call (in the servlet)?
0
objectsCommented:
yes thats correct

try {
   manager.register(...
} catch (Exception ex) {
   res.sendRedirect("/Fergal/EmployeeRegister.html");
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oggiemcAuthor Commented:
thanx a mill objects!! thats working now..if you dont mind me askin, why couldnt i throw and catch the exception from the register method??
0
objectsCommented:
because the servlet would have no idea that it had been redirected and would continue normal processing
0
oggiemcAuthor Commented:
i see..thanks for your help!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java App Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.