File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp question - errorPage

 
H Singh
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
H Singh
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did u change the other one too i mean in your error file

<%@ page isErrorPage="true" %>
 
H Singh
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup i changed in both jsp's
 
Teddy
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changed null to "" as you recommended, still no luck
 
Teddy
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic