0

Spring boot error-page. This application has no explicit mapping for /error.

asked 2019-10-23 22:15:06 +0800

Evgenic gravatar image Evgenic
14 3

updated 2019-10-23 22:16:41 +0800

Hello,

Zk8 under spring boot. How to map error-page? Where is no web.xml but code in 'resources/metainfo/zk/zk.xml' as

<error-page>
    <exception-type>java.lang.Throwable</exception-type>
    <location>/error.zul</location>
</error-page>

doesn't work.

I have a file 'error.zul' in folder 'resources/web'. But URL becomes as 'http://localhost:8085/zkau/web/c931702b/selectService.zul'. I don't know what is 'c931702b'. The file 'selectService.zul' just in folder 'web' too.

I mapped the home page in application.yml as

zk:
  homepage: index

Then 'index.zul' is opening well. But other *.zul from 'web' opened by URL with 'c931702b'. It is OK too. What I should do for mapping of the error-page?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2019-10-24 16:05:52 +0800

Evgenic gravatar image Evgenic
14 3

A solution by spring-boot:

@RestController
public class MyErrorController implements ErrorController {

    @RequestMapping("/error")
    public String handleError(HttpServletRequest request, HttpServletResponse httpResponse) throws IOException {
        Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
        if (status != null) {
            Integer statusCode = Integer.valueOf(status.toString());
            if (statusCode == HttpStatus.NOT_FOUND.value()) {
                return "error-404";
            } else if (statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
                httpResponse.sendRedirect("error.zul");
                return null;
            }
        }
        return "error";
    }

    @Override
    public String getErrorPath() {
        return "/error";
    }
}

It is enough for redirecting on error.zul.

link publish delete flag offensive edit
0

answered 2019-10-28 12:30:53 +0800

cor3000 gravatar image cor3000
4887 2 7
ZK Team

yea, seems like you found one of the available options spring boot offers:

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-error-handling

I could imagine a problem with errors during AJAX requests (that's what the configuration in zk.xml is for).

If you read our Error handling document you'll notice that ZK has 2 kinds of error handlers. One in web.xml and one in zk.xml.

The web.xml part has to be configured the spring-boot way. The Ajax error configuration still has to go into zk.xml, in order to provide reasonable responses for AJAX based errors.

If you just want a static error page for 404 errors, I'd prefer the static HTML file convention inside spring boot's static resources (https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-error-handling-custom-error-pages). This will prevent ZK from initializing desktop objects inside your session, just to display something isn't actually there.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2019-10-23 22:15:06 +0800

Seen: 8 times

Last updated: Oct 28

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More