Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 750
tommi Avatar asked Nov 02 '12 01:11

tommi


2 Answers

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.

like image 99
tommi Avatar answered Oct 14 '22 00:10

tommi


Why don't you use a Java EE <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.

like image 36
siomes Avatar answered Oct 14 '22 00:10

siomes