• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp question - errorPage

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yup i changed in both jsp's
 
Teddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
changed null to "" as you recommended, still no luck
 
Teddy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic