You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Sumit Bhardwaj <su...@gmail.com> on 2019/12/03 12:11:14 UTC

Global Error Handling

Hi Experts,

We have a requirement from a customer, where in case of 404, where someone
is putting an invalid url, instead of showing the default error, we should
be showing a custom message.

Is this possible?

I have searched and found couple of solutions similar to
https://stackoverflow.com/questions/27859626/tomcat-server-change-default-http-404


but these did not work, these work at the app level, but not globally on
tomcat level.

e.g. if i have an app called myapp

http://<server address>/myapp/<invalid path> This  works and it gets
redirected to custom page

but

http://<server address>/<invalid App>, This does not work and 404 is shown,

Is there someway we can handle errors at global level on tomca.t

We are using tomcat 9.0.24.

Thanks for your help.

Best
Sumit Bhardwaj

Re: [E] Global Error Handling

Posted by "Bauer, Margaret M (Peggy)" <ma...@verizon.com.INVALID>.
I think you can add your customized jsp page within your web.xml by
modifying path and file name

 <error-page>
    <error-code>401</error-code>
    <location>/WEB-INF/jsp/401.jsp</location>
  </error-page>
  <error-page>
    <error-code>403</error-code>
    <location>/WEB-INF/jsp/403.jsp</location>
  </error-page>
  <error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/jsp/404.jsp</location>
  </error-page>

On Tue, Dec 3, 2019 at 8:11 AM Sumit Bhardwaj <su...@gmail.com>
wrote:

> Hi Experts,
>
> We have a requirement from a customer, where in case of 404, where someone
> is putting an invalid url, instead of showing the default error, we should
> be showing a custom message.
>
> Is this possible?
>
> I have searched and found couple of solutions similar to
>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com_questions_27859626_tomcat-2Dserver-2Dchange-2Ddefault-2Dhttp-2D404&d=DwIBaQ&c=udBTRvFvXC5Dhqg7UHpJlPps3mZ3LRxpb6__0PomBTQ&r=JYuCIQ8r7H-c_yYFTZ4gdv4goO0lCCtidMRmNza4zoA&m=W70UQy0yQZ6RcqlHmp6JmY1-JKse-vhMHnH9vleLY7o&s=rhOgsU2tAGMdFGQL-8RDhOtdkd11pYl5mOR1R4rQNKI&e=
>
>
> but these did not work, these work at the app level, but not globally on
> tomcat level.
>
> e.g. if i have an app called myapp
>
> http://<server address>/myapp/<invalid path> This  works and it gets
> redirected to custom page
>
> but
>
> http://<server address>/<invalid App>, This does not work and 404 is
> shown,
>
> Is there someway we can handle errors at global level on tomca.t
>
> We are using tomcat 9.0.24.
>
> Thanks for your help.
>
> Best
> Sumit Bhardwaj
>


-- 
*Peggy Bauer*
CAO Production Support
214-770-1782

Re: Global Error Handling

Posted by Mark Thomas <ma...@apache.org>.
On 03/12/2019 12:50, logo wrote:
> Sumit,
> 
> 
> Am 2019-12-03 13:11, schrieb Sumit Bhardwaj:
>> Hi Experts,
>>
>> We have a requirement from a customer, where in case of 404, where
>> someone
>> is putting an invalid url, instead of showing the default error, we
>> should
>> be showing a custom message.
>>
>> Is this possible?
>>
>> I have searched and found couple of solutions similar to
>> https://stackoverflow.com/questions/27859626/tomcat-server-change-default-http-404
>>
>>
>>
>> but these did not work, these work at the app level, but not globally on
>> tomcat level.
> 
> this can also be configured on the global web.xml.

No, it can't. conf/web.xml provides defaults for web applications, not
global settings.

> An alternative way
> would be a CustomErrorReportValve that can be configured on the
> Host-Element in server.xml.

It would but, that is an overly complex solution.

There are two better - in my view - options.

1. Deploy a ROOT web application with appropriate error page
configuration. This will catch all URLs that aren't mapped to any other
deployed applications.

2. Use errorCode.0="..." and/or exceptionType.java.lang.Throwable="..."
attributes of the ErrorReportValve to define static web pages for those
errors.

http://tomcat.apache.org/tomcat-9.0-doc/config/valve.html#Error_Report_Valve/Attributes

Mark

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


Re: Global Error Handling

Posted by logo <lo...@kreuser.name>.
Sumit,


Am 2019-12-03 13:11, schrieb Sumit Bhardwaj:
> Hi Experts,
> 
> We have a requirement from a customer, where in case of 404, where 
> someone
> is putting an invalid url, instead of showing the default error, we 
> should
> be showing a custom message.
> 
> Is this possible?
> 
> I have searched and found couple of solutions similar to
> https://stackoverflow.com/questions/27859626/tomcat-server-change-default-http-404
> 
> 
> but these did not work, these work at the app level, but not globally 
> on
> tomcat level.

this can also be configured on the global web.xml. An alternative way 
would be a CustomErrorReportValve that can be configured on the 
Host-Element in server.xml.

       <Host name="localhost" appBase="webapps" unpackWARs="false" 
autoDeploy="false" deployXML="true" 
errorReportValveClass="whatever.tomcat.valves.CustomErrorReportValve">

see: 
https://tomcat.apache.org/tomcat-8.5-doc/config/host.html#Common_Attributes 
-> errorReportValveClass

One link I found is 
https://aspiresoftware.in/blog/catalinatomcat-custom-error-report-valve-to-handle-errors-exceptions/

Best regards

Peter

> 
> e.g. if i have an app called myapp
> 
> http://<server address>/myapp/<invalid path> This  works and it gets
> redirected to custom page
> 
> but
> 
> http://<server address>/<invalid App>, This does not work and 404 is 
> shown,
> 
> Is there someway we can handle errors at global level on tomca.t
> 
> We are using tomcat 9.0.24.
> 
> Thanks for your help.
> 
> Best
> Sumit Bhardwaj

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