How to implement a custom 404 error page on App Engine, Java?

221 views
Skip to first unread message

tommi via StackOverflow

unread,
Nov 1, 2012, 9:26:49 PM11/1/12
to google-appengin...@googlegroups.com

Hi I'm trying to set up a static error page for 404 not found errors on app engine.

According to https://developers.google.com/appengine/docs/java/config/webxml#Error_Handlers: it says 404 cannot be customized.

And according to: https://developers.google.com/appengine/docs/java/config/appconfig#Custom_Error_Responses it don't seem to support 404 too.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/13187970/how-to-implement-a-custom-404-error-page-on-app-engine-java

Thanos Makris via StackOverflow

unread,
Nov 2, 2012, 4:22:01 AM11/2/12
to google-appengin...@googlegroups.com

You are correct, this is not currently available in Java on App Engine. However, there is a workaround for Python. For an example on this, you can take a look at GAE Boilerplate.

Hope this helps.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/13187970/how-to-implement-a-custom-404-error-page-on-app-engine-java/13191567#13191567

siomes via StackOverflow

unread,
Nov 2, 2012, 6:22:01 AM11/2/12
to google-appengin...@googlegroups.com

Why don't use JEE <error-page> entry for these purposes?

in your web.xml:

<error-page>
    <error-code>404</error-code>
    <location>/app/error/404</location>
</error-page>
....
<error-page>
    <error-code>500</error-code>
    <location>/app/error/500</location>
</error-page>

You can combine it with Spring and get a general error-controller like:

....   
@Controller
public class ErrorController {

@RequestMapping(value = "/error/{errorCode}")
public final String errorCode(
        @PathVariable("errorCode") final String errorCode,
        final ModelMap modelMap) {
    modelMap.put("statusCode", errorCode);
    return "redirect:/ui/error.htm";
}

and your jsp-like file:

<h2>Error!!!</h2>
....
<h3>Status code: #{param.statusCode}</h3>

Hope this helps.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/13187970/how-to-implement-a-custom-404-error-page-on-app-engine-java/13193300#13193300

tommi via StackOverflow

unread,
Nov 3, 2012, 8:18:46 AM11/3/12
to google-appengin...@googlegroups.com

Hi I'm trying to set up a static error page for 404 not found errors on app engine.

According to https://developers.google.com/appengine/docs/java/config/webxml#Error_Handlers: it says 404 cannot be customized.

And according to: https://developers.google.com/appengine/docs/java/config/appconfig#Custom_Error_Responses it don't seem to support 404 too.

However, https://groups.google.com/forum/?fromgroups=#!topic/google-appengine-java/3C-pY5ta2HQ, seems to suggest that 404 error page can be customised. I'm confused right now.

tommi via StackOverflow

unread,
Nov 3, 2012, 11:05:05 PM11/3/12
to google-appengin...@googlegroups.com

i realised this problem happens when running the app on local dev server. however, when i deploy the app to app engine. i can see the 404 error page that was configured using web.xml. thanks for all your help.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/13187970/how-to-implement-a-custom-404-error-page-on-app-engine-java/13215692#13215692
Reply all
Reply to author
Forward
0 new messages