Forums Register Login

<%@page errorPage="<file-name>"%> not Working.

+Pie Number of slices to send: Send
I am writing following code:

<%@page errorPage="Error.jsp"%>

<%

String user = (String)request.getParameter("uname");

String password = (String) request.getParameter("password");

try{
if(user.equals("Prathamesh") && password.equals("India")){

out.println("Welcome");

out.flush();

RequestDispatcher rd = request.getRequestDispatcher("/Welcome.jsp");

rd.include(request, response);


}else{
throw new Exception();
}

}catch(Exception e){
throw new Exception("Servlet Error");
}

%>

Whenever i enter wrong password it should go to Error.jsp which is as follows:

<%@page isErrorPage="true" %>

Error Welcome !

<%= exception.getMessage() %>


But it gives Http 500

The website cannot display the page
HTTP 500
Most likely causes:
The website is under maintenance.
The website has a programming error.

Help will be much appriciated.

Regards,
Prathamesh.
+Pie Number of slices to send: Send
Hi prathamesh,

First of all use code tags for code segments it will be easy to read.

When are you getting 500 while visiting your login JSP or after try to login...?
+Pie Number of slices to send: Send
When i m trying to login, i have given a dummy logic hardcoding the uname and password.

if the uname and password do not match , the processing logic throws Exception.

Just to demonstrate the errorPAge attribute of the Page Directive i m using this exception.

If i use try-catch block in the processing, it works. But do no transfer the command to ErrorPage(which is intended).

If i remove that try-catch...It gives Http 500 error.

Login.jsp >>> LoginProcess.jsp(Process Logic)>>>> If Successful >>>> Welcome.jsp
If Failed >>>> Error.jsp
+Pie Number of slices to send: Send
Are your Login.jsp & Error.jsp in same folder in web application?
+Pie Number of slices to send: Send
yes. they are in the same folder. outside WEB-INF.
Willie Smits can speak 40 languages. This tiny ad can speak only one:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1300 times.
Similar Threads
Returning a result set in an html form
JSP and custom Exception class
Encoding errorPage url
simple errorPage question
response.sendError & error-page
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:31:58.