You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark Liu <ma...@yahoo.com> on 2003/05/17 08:26:03 UTC

How to have a customized error page?

If we request a page which does not exist, we see
this:

HTTP Status 404 - /badrequest.html
---------------------------
type Status report

message /badrequest.html
description The requested resource (/badrequest.html)
is not available.
---------------------------
Apache Tomcat/4.1.24

How can I have a customized error message like so:

Sorry, the page cannot be found!

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: At my wits' end: Using JavaBean in JSP

Posted by William Wragg <wi...@datapro.co.uk>.
Jasper compiles my Beans for me. What I do is clear out the 
$CATALINA_HOME/work/Standalone/localhost/MyApp and then when Japser 
compiles the JSP's for the first time and there are no classes (or the java 
source has changed) for the Bean, it will compile the Bean for me when it 
is used in a page. This is using 4.0.4 is it different for later versions?

At 09:59 23/05/2003, you wrote:

>If this file is correct (typo excepted)
>/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java
>then the problem is that you need to deploy the compiled class file and 
>not the source. Jasper doesn't compile beans for you.
>
>Mark Liu wrote:
>>I searched the Web for a while, and found that quite
>>many people had the same problem.  But no one solution
>>I found on the Web solved the problem.
>>The problem is that my JSP page just can't get
>>compiled. And here are the exceptions:
>>org.apache.jasper.JasperException:
>>coreservlets.StringBean
>>   [snip]
>>java.lang.ClassNotFoundException:
>>coreservlets.StringBean
>>   [snip]
>>Before you take it for granted that it's a path
>>problem, I do have the correct path for everything!
>>I did try <%@ page import="coreservlets.StringBean" %>
>>at the top of the jsp page, it does not help!
>>*** The Bean class is from *************
>>*** Marty Hall's Core Servlets *********
>>*** and so is the StringBean.jsp***
>>package coreservlets;
>>public class StringBean {
>>   private String message = "No message specified";
>>   // Some people suggested that I
>>   // add the default constructor, which
>>   // does not help solve the problem.
>>   public StringBean()
>>   {}
>>   public String getMessage() {
>>     return(message);
>>   }
>>   public void setMessage(String message) {
>>     this.message = message;
>>   }
>>}
>>*** And the JSP page is right here ****
>><!-- this import below does not help -->
>><%@ page import="coreservlets.StringBean" %>
>><HTML>
>><HEAD>
>><TITLE>Using JavaBeans with JSP</TITLE>
>></HEAD>
>><BODY>
>><TABLE BORDER=5 ALIGN="CENTER">
>>   <TR><TH CLASS="TITLE">
>>       Using JavaBeans with JSP</TABLE>
>>
>><jsp:useBean id="stringBean"
>>class="coreservlets.StringBean" />
>><OL>
>><LI>Initial value (getProperty):
>><!-- the problem persists even if I do
>>      name="coreservlets.stringBean" below
>>-->
>>     <I><jsp:getProperty 
>> name="stringBean"                         property="message" /></I>
>><LI>Initial value (JSP expression):
>>     <I><%= stringBean.getMessage() %></I>
>><LI><jsp:setProperty 
>>name="stringBean"                      property="message" 
>>      value="Best string bean: Fortex"
>>/>
>>     Value after setting property with setProperty:
>>     <I><jsp:getProperty 
>> name="stringBean"                         property="message" /></I>
>><LI><% stringBean.setMessage("My favorite: Kentucky
>>Wonder"); %>
>>     Value after setting property with scriptlet:
>>     <I><%= stringBean.getMessage() %></I>
>></OL>
>>
>></BODY>
>></HTML>
>>*** end of the JSP ***
>>On the Solaris system where I run tomcat4.1.24, the
>>Bean file is at
>>/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java
>>and the JSP is at
>>/export/home/tomcat4.1.24/webapps/ROOT/StringBean.jsp
>>My tomcat server is running well, servlets work just
>>great.
>>This is the first time I try working with JavaBeans
>>and got so much trouble.  Really do not understand why
>>I am getting those exceptions.  Any idea please?
>>
>>__________________________________
>>Do you Yahoo!?
>>The New Yahoo! Search - Faster. Easier. Bingo.
>>http://search.yahoo.com
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
>---
>Incoming mail is certified Virus Free.
>Checked by AVG anti-virus system (http://www.grisoft.com).
>Version: 6.0.483 / Virus Database: 279 - Release Date: 19/05/2003

Re: At my wits' end: Using JavaBean in JSP

Posted by Jon Wingfield <jo...@mkodo.com>.
If this file is correct (typo excepted)
/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java
then the problem is that you need to deploy the compiled class file and 
not the source. Jasper doesn't compile beans for you.

Mark Liu wrote:
> I searched the Web for a while, and found that quite
> many people had the same problem.  But no one solution
> I found on the Web solved the problem.
> 
> The problem is that my JSP page just can't get
> compiled. And here are the exceptions:
> 
> org.apache.jasper.JasperException:
> coreservlets.StringBean
>   [snip]
> java.lang.ClassNotFoundException:
> coreservlets.StringBean
>   [snip]
> 
> Before you take it for granted that it's a path
> problem, I do have the correct path for everything!
> 
> I did try <%@ page import="coreservlets.StringBean" %>
> at the top of the jsp page, it does not help!
> 
> *** The Bean class is from *************
> *** Marty Hall's Core Servlets *********
> *** and so is the StringBean.jsp***
> 
> package coreservlets;
> 
> public class StringBean {
>   private String message = "No message specified";
> 
>   // Some people suggested that I
>   // add the default constructor, which
>   // does not help solve the problem.
> 
>   public StringBean()
>   {}
> 
>   public String getMessage() {
>     return(message);
>   }
> 
>   public void setMessage(String message) {
>     this.message = message;
>   }
> }
> 
> *** And the JSP page is right here ****
> 
> <!-- this import below does not help -->
> <%@ page import="coreservlets.StringBean" %> 
> 
> <HTML>
> <HEAD>
> <TITLE>Using JavaBeans with JSP</TITLE>
> </HEAD>
> 
> <BODY>
> 
> <TABLE BORDER=5 ALIGN="CENTER">
>   <TR><TH CLASS="TITLE">
>       Using JavaBeans with JSP</TABLE>
>  
> <jsp:useBean id="stringBean"
> class="coreservlets.StringBean" />
> 
> <OL>
> <LI>Initial value (getProperty):
> 
> <!-- the problem persists even if I do
>      name="coreservlets.stringBean" below
> -->
> 
>     <I><jsp:getProperty name="stringBean" 
>                         property="message" /></I>
> 
> <LI>Initial value (JSP expression):
>     <I><%= stringBean.getMessage() %></I>
> <LI><jsp:setProperty name="stringBean" 
>                      property="message" 
>                      value="Best string bean: Fortex"
> />
>     Value after setting property with setProperty:
>     <I><jsp:getProperty name="stringBean" 
>                         property="message" /></I>
> 
> <LI><% stringBean.setMessage("My favorite: Kentucky
> Wonder"); %>
>     Value after setting property with scriptlet:
>     <I><%= stringBean.getMessage() %></I>
> </OL>
>              
> </BODY>
> </HTML>
> *** end of the JSP ***
> 
> On the Solaris system where I run tomcat4.1.24, the
> Bean file is at
> /export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java
> 
> and the JSP is at
> /export/home/tomcat4.1.24/webapps/ROOT/StringBean.jsp
> 
> My tomcat server is running well, servlets work just
> great.
> 
> This is the first time I try working with JavaBeans
> and got so much trouble.  Really do not understand why
> I am getting those exceptions.  Any idea please?
> 
> 
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: At my wits' end: Using JavaBean in JSP: sorry for a typo

Posted by Mark Liu <ma...@yahoo.com>.
Sorry, in the previous message I have a typo
"corsevlets".

Please note that it is just a typo in that message.  I
do have the correct spelling "coreservlets" on my
system.

> On the Solaris system where I run tomcat4.1.24, the
> Bean file is at
>
/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


At my wits' end: Using JavaBean in JSP

Posted by Mark Liu <ma...@yahoo.com>.
I searched the Web for a while, and found that quite
many people had the same problem.  But no one solution
I found on the Web solved the problem.

The problem is that my JSP page just can't get
compiled. And here are the exceptions:

org.apache.jasper.JasperException:
coreservlets.StringBean
  [snip]
java.lang.ClassNotFoundException:
coreservlets.StringBean
  [snip]

Before you take it for granted that it's a path
problem, I do have the correct path for everything!

I did try <%@ page import="coreservlets.StringBean" %>
at the top of the jsp page, it does not help!

*** The Bean class is from *************
*** Marty Hall's Core Servlets *********
*** and so is the StringBean.jsp***

package coreservlets;

public class StringBean {
  private String message = "No message specified";

  // Some people suggested that I
  // add the default constructor, which
  // does not help solve the problem.

  public StringBean()
  {}

  public String getMessage() {
    return(message);
  }

  public void setMessage(String message) {
    this.message = message;
  }
}

*** And the JSP page is right here ****

<!-- this import below does not help -->
<%@ page import="coreservlets.StringBean" %> 

<HTML>
<HEAD>
<TITLE>Using JavaBeans with JSP</TITLE>
</HEAD>

<BODY>

<TABLE BORDER=5 ALIGN="CENTER">
  <TR><TH CLASS="TITLE">
      Using JavaBeans with JSP</TABLE>
 
<jsp:useBean id="stringBean"
class="coreservlets.StringBean" />

<OL>
<LI>Initial value (getProperty):

<!-- the problem persists even if I do
     name="coreservlets.stringBean" below
-->

    <I><jsp:getProperty name="stringBean" 
                        property="message" /></I>

<LI>Initial value (JSP expression):
    <I><%= stringBean.getMessage() %></I>
<LI><jsp:setProperty name="stringBean" 
                     property="message" 
                     value="Best string bean: Fortex"
/>
    Value after setting property with setProperty:
    <I><jsp:getProperty name="stringBean" 
                        property="message" /></I>

<LI><% stringBean.setMessage("My favorite: Kentucky
Wonder"); %>
    Value after setting property with scriptlet:
    <I><%= stringBean.getMessage() %></I>
</OL>
             
</BODY>
</HTML>
*** end of the JSP ***

On the Solaris system where I run tomcat4.1.24, the
Bean file is at
/export/home/tomcat4.1.24/webapps/ROOT/WEB-INF/classes/corsevlets/StringBean.java

and the JSP is at
/export/home/tomcat4.1.24/webapps/ROOT/StringBean.jsp

My tomcat server is running well, servlets work just
great.

This is the first time I try working with JavaBeans
and got so much trouble.  Really do not understand why
I am getting those exceptions.  Any idea please?


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How to have a customized error page?

Posted by Mark Liu <ma...@yahoo.com>.
Hi, the path you provide between the location tag
*must* start with /, otherwise, you can't start the
server.

This also implies that
http://yourhost:port/error/404.html will not work.

Any idea?

--- Werner van Mook <we...@connecties.com> wrote:
> HI,
> 
> Haven't you maybe forgotten the starting / in the
> <location> tag?
> If I'm correct this makes the path to the error page
> absolute.
> Otherwise you could also make the location a
> complete URL as in :
> http://yourhost:port/error/404.html
> 
> I haven't tried that so I'm not sure if it will be
> working correctly.
> 
> Werner
> 
> 
> On Sunday, May 18, 2003, at 08:47 AM, Mark Liu
> wrote:
> 
> > Thanks.  This works.
> >
> > But there is a little problem.  It seems that I
> cannot
> > specify an absolute path to the error page.
> >
> > Say, if the name of my web application is myweb
> and if
> > the server receives a request
> >
> > http://www.myserver.com/myweb/badrequest.html,
> >
> > My web server will present
> >
> > http://www.myserver.com/myweb/error/404.html,
> which is
> > OK and works as expected.
> >
> > But if the server receives a request for
> >
> >
>
http://www.myserver.com/myweb/no_such_folder/badrequest.html,
> >
> >
> > then my server will attempt to present
> >
> >
>
http://www.myserver.com/myweb/no_such_folder/error/404.html,
> >
> >
> > which is certainly bad, since no_such_folder does
> not
> > exist on my server.
> >
> > You see the point?
> >
> > In conclusion, I want my server to present
> > http://www.myserver.com/myweb/error/404.html for
> all
> > bad requests.  How to handle this?
> >
> > Thanks
> >
> > --- Werner van Mook <we...@connecties.com> wrote:
> >> To create custom error list add the following to
> >> web.xml :
> >>
> >>
> >> <error-page>
> >>      <error-code>404</error-code>
> >>      <location>/error/404.html</location>
> >> </error-page>
> >>
> >> you have to adjust the location to the location
> of
> >> your error page.
> >>
> >> Werner
> >>
> >> On Saturday, May 17, 2003, at 08:26 AM, Mark Liu
> >> wrote:
> >>
> >>> If we request a page which does not exist, we
> see
> >>> this:
> >>>
> >>> HTTP Status 404 - /badrequest.html
> >>> ---------------------------
> >>> type Status report
> >>>
> >>> message /badrequest.html
> >>> description The requested resource
> >> (/badrequest.html)
> >>> is not available.
> >>> ---------------------------
> >>> Apache Tomcat/4.1.24
> >>>
> >>> How can I have a customized error message like
> so:
> >>>
> >>> Sorry, the page cannot be found!
> >>>
> >>> __________________________________
> >>> Do you Yahoo!?
> >>> The New Yahoo! Search - Faster. Easier. Bingo.
> >>> http://search.yahoo.com
> >>>
> >>>
> >>
> >
>
---------------------------------------------------------------------
> >>> To unsubscribe, e-mail:
> >> tomcat-user-unsubscribe@jakarta.apache.org
> >>> For additional commands, e-mail:
> >> tomcat-user-help@jakarta.apache.org
> >>>
> >>
> >>
> >>
> >
>
---------------------------------------------------------------------
> >> To unsubscribe, e-mail:
> >> tomcat-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail:
> >> tomcat-user-help@jakarta.apache.org
> >>
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > The New Yahoo! Search - Faster. Easier. Bingo.
> > http://search.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
> >
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How to have a customized error page?

Posted by Werner van Mook <we...@connecties.com>.
HI,

Haven't you maybe forgotten the starting / in the <location> tag?
If I'm correct this makes the path to the error page absolute.
Otherwise you could also make the location a complete URL as in :
http://yourhost:port/error/404.html

I haven't tried that so I'm not sure if it will be working correctly.

Werner


On Sunday, May 18, 2003, at 08:47 AM, Mark Liu wrote:

> Thanks.  This works.
>
> But there is a little problem.  It seems that I cannot
> specify an absolute path to the error page.
>
> Say, if the name of my web application is myweb and if
> the server receives a request
>
> http://www.myserver.com/myweb/badrequest.html,
>
> My web server will present
>
> http://www.myserver.com/myweb/error/404.html, which is
> OK and works as expected.
>
> But if the server receives a request for
>
> http://www.myserver.com/myweb/no_such_folder/badrequest.html,
>
>
> then my server will attempt to present
>
> http://www.myserver.com/myweb/no_such_folder/error/404.html,
>
>
> which is certainly bad, since no_such_folder does not
> exist on my server.
>
> You see the point?
>
> In conclusion, I want my server to present
> http://www.myserver.com/myweb/error/404.html for all
> bad requests.  How to handle this?
>
> Thanks
>
> --- Werner van Mook <we...@connecties.com> wrote:
>> To create custom error list add the following to
>> web.xml :
>>
>>
>> <error-page>
>>      <error-code>404</error-code>
>>      <location>/error/404.html</location>
>> </error-page>
>>
>> you have to adjust the location to the location of
>> your error page.
>>
>> Werner
>>
>> On Saturday, May 17, 2003, at 08:26 AM, Mark Liu
>> wrote:
>>
>>> If we request a page which does not exist, we see
>>> this:
>>>
>>> HTTP Status 404 - /badrequest.html
>>> ---------------------------
>>> type Status report
>>>
>>> message /badrequest.html
>>> description The requested resource
>> (/badrequest.html)
>>> is not available.
>>> ---------------------------
>>> Apache Tomcat/4.1.24
>>>
>>> How can I have a customized error message like so:
>>>
>>> Sorry, the page cannot be found!
>>>
>>> __________________________________
>>> Do you Yahoo!?
>>> The New Yahoo! Search - Faster. Easier. Bingo.
>>> http://search.yahoo.com
>>>
>>>
>>
> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail:
>> tomcat-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:
>> tomcat-user-help@jakarta.apache.org
>>>
>>
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> tomcat-user-help@jakarta.apache.org
>>
>
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How to have a customized error page?

Posted by Mark Liu <ma...@yahoo.com>.
Thanks.  This works.

But there is a little problem.  It seems that I cannot
specify an absolute path to the error page.

Say, if the name of my web application is myweb and if
the server receives a request

http://www.myserver.com/myweb/badrequest.html,

My web server will present 

http://www.myserver.com/myweb/error/404.html, which is
OK and works as expected.

But if the server receives a request for 

http://www.myserver.com/myweb/no_such_folder/badrequest.html,


then my server will attempt to present

http://www.myserver.com/myweb/no_such_folder/error/404.html,


which is certainly bad, since no_such_folder does not
exist on my server.

You see the point?  

In conclusion, I want my server to present
http://www.myserver.com/myweb/error/404.html for all
bad requests.  How to handle this?

Thanks

--- Werner van Mook <we...@connecties.com> wrote:
> To create custom error list add the following to
> web.xml :
> 
> 
> <error-page>
>      <error-code>404</error-code>
>      <location>/error/404.html</location>
> </error-page>
> 
> you have to adjust the location to the location of
> your error page.
> 
> Werner
> 
> On Saturday, May 17, 2003, at 08:26 AM, Mark Liu
> wrote:
> 
> > If we request a page which does not exist, we see
> > this:
> >
> > HTTP Status 404 - /badrequest.html
> > ---------------------------
> > type Status report
> >
> > message /badrequest.html
> > description The requested resource
> (/badrequest.html)
> > is not available.
> > ---------------------------
> > Apache Tomcat/4.1.24
> >
> > How can I have a customized error message like so:
> >
> > Sorry, the page cannot be found!
> >
> > __________________________________
> > Do you Yahoo!?
> > The New Yahoo! Search - Faster. Easier. Bingo.
> > http://search.yahoo.com
> >
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
> >
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: How to have a customized error page?

Posted by Werner van Mook <we...@connecties.com>.
To create custom error list add the following to web.xml :


<error-page>
     <error-code>404</error-code>
     <location>/error/404.html</location>
</error-page>

you have to adjust the location to the location of your error page.

Werner

On Saturday, May 17, 2003, at 08:26 AM, Mark Liu wrote:

> If we request a page which does not exist, we see
> this:
>
> HTTP Status 404 - /badrequest.html
> ---------------------------
> type Status report
>
> message /badrequest.html
> description The requested resource (/badrequest.html)
> is not available.
> ---------------------------
> Apache Tomcat/4.1.24
>
> How can I have a customized error message like so:
>
> Sorry, the page cannot be found!
>
> __________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo.
> http://search.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org