tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leonard Afeng <afeng.leon...@gmail.com>
Subject 答复: [Tomcat] Error page not work for 400 error.
Date Mon, 06 Aug 2018 00:51:56 GMT
Thanks Mark,

1. The web.xml is defind in the {$TOMCAT_HOME} /conf , not in application.
2. I add some walk around code in the ErrorPageSupport.java
3.     public ErrorPage find(int statusCode) {
4.         log.info("before find, the length of statusPages is:"+statusPages.size());    

5.     	
6.     	log.info("in addErrorPage find by status Code ************ code is:"+statusCode );
7.     	log.info(Integer.valueOf(statusCode));
8.     	if ( statusPages.get(Integer.valueOf(statusCode)) == null )
9.     		log.info("cannot find for "+statusCode);
10.     	else
11.     		log.info("find:"+statusPages.get(Integer.valueOf(statusCode)).getLocation() );
12.     	
13.     	if ( statusCode == 400 ) {
14.     		log.info("%%%%%%%%%% use custom errorpage");
15.     		ErrorPage ep =new ErrorPage();
16.     		ep.setErrorCode(400);
17.     		ep.setLocation("\400.html");
18.     		return ep;
19.     	}else
20.     	     return statusPages.get(Integer.valueOf(statusCode));
21.     }

This code was reached but the return was not worked.

发送自 Windows 10 版邮件应用

发件人: Mark Thomas
发送时间: 2018年8月6日 3:32
收件人: users@tomcat.apache.org
主题: Re: [Tomcat] Error page not work for 400 error.

On 05/08/2018 04:13, Leonard Afeng wrote:
>   Dear all,
> 
> I custom the error page in web.xml as below:

<snip/>

> And I added some log action in org.apache.catalina.util.ErrorPageSupport
> and found out that in some case the 400 error page not working but the
> default error page.

<snip/>

> 20:02:59.674 INFO [http-nio-8080-exec-1]
> org.apache.coyote.http11.Http11Processor.service
> Error parsing HTTP request header

<snip/>

> Is it a known bug 

No.

> or I can get some patch for it ?

No.

What you are asking for is logically impossible.

The request parsing has failed. Therefore Tomcat can't (reliably) 
identify the web application the request should be routed to. Therefore 
you can't have an application error page generate a response.

If you are using 9.0.6 onwards, the ErrorReportValve can be configured 
to return a custom *static* page for any specific error code and/or 
Exception.

Mark

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



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message