permaculture playing cards*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp question  - errorPage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp question  - errorPage" Watch "jsp question  - errorPage" New topic
Author

jsp question - errorPage

H Singh
Ranch Hand

Joined: Apr 03, 2005
Posts: 34
I have testing isErrorPage

my jsp files are: hello.jsp and errorHandler.jsp

<!@ page errorPage="errorHandler.jsp" %>
<html>
<body>

<% if(request.getParameter("username")==null){
throw new RuntimeException("Name not specified");
}
%>
Hello, <%= request.getParameter("username") %>
</body>
</html>

<!@ page isErrorPage="true" %>

<html><body>

Unable to process <%= exception.getMessage() %>

</body></html>

and form.html as

<html><body>
<h1 align="center">Error Page Test </h1>
<form method="POST" action="hello.jsp">
Enter your name<p>

<input type="text" name="username" size="20"><br>
<center>
<input type="submit">
</center>
</form></body></html>


when i do not type a name in the box, should'nt i get

Unable to process : Name not specified

instead i get

Hello,
[ May 30, 2005: Message edited by: H Singh ]
Teddy
Greenhorn

Joined: May 30, 2005
Posts: 16
i think u should use <%@ page .... %>

instead of

<!@ page errorPage="errorHandler.jsp" %>


you still might not be able to get your error page because with IE your error page should be grater than some specific number of bytes (i think 360 ) so either make a longer error page or in the options of internet explorer under advanced tab uncheck show friendly HTTP error messages.

Let me know if it works.


SCJP SCWCD SCBCD(preparing)
H Singh
Ranch Hand

Joined: Apr 03, 2005
Posts: 34
I changed
<!@ page errorPage="errorHandler.jsp" %>

to

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

and unchecked "show friendly HTTP error messages" but it did not work.

Thanks
Teddy
Greenhorn

Joined: May 30, 2005
Posts: 16
did u change the other one too i mean in your error file

<%@ page isErrorPage="true" %>
H Singh
Ranch Hand

Joined: Apr 03, 2005
Posts: 34
yup i changed in both jsp's
Teddy
Greenhorn

Joined: May 30, 2005
Posts: 16
Well that's because request.getParamter("username") would not return if the parameter doesnt exist. So if you change your if statement and compare with "" instead of null, it should work.
Teddy
Greenhorn

Joined: May 30, 2005
Posts: 16
i am sorry i missed null word from previous message i meant it wont return null even if the parameter doesnt exist.
H Singh
Ranch Hand

Joined: Apr 03, 2005
Posts: 34
changed null to "" as you recommended, still no luck
Teddy
Greenhorn

Joined: May 30, 2005
Posts: 16
well i tried and it worked on my machine. can u try throwing the exception without if clause i mean just throw the exception atleast then we would know what part is wrong
H Singh
Ranch Hand

Joined: Apr 03, 2005
Posts: 34
Thanks a lot T Singh for looking into this

I tried :

<%@ page errorPage="errorHandler.jsp" %>
<html>
<body>

<%
if(request.getParameter("name")==null){
%>


Hi there

<%
}
%>

</body>
</html>

and it worked...so if clause is fine
 
wood burning stoves
 
subject: jsp question - errorPage
 
Similar Threads
regarding page directive: errorPage
Page Directive errorPage and isErrorPage
Want my exceptions to be caught by errorPage JSP ?
curious case of JSP page passing empty string,instead of passing null value
difficulty in understanding <jsp:forward page=" " />and unusual code execution.