Java Code Examples for com.jfinal.core.Controller#redirect()

The following examples show how to use com.jfinal.core.Controller#redirect() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParaValidateInterceptor.java    From jboot with Apache License 2.0 5 votes vote down vote up
private void renderError(Controller controller, String renderType, String formName, String message, String redirectUrl, String htmlPath, int errorCode) {
    switch (renderType) {
        case ValidateRenderType.DEFAULT:
            if (RequestUtil.isAjaxRequest(controller.getRequest())) {
                controller.renderJson(
                        Ret.fail("message", message)
                                .set("errorCode", errorCode)
                                .setIfNotNull("formName", formName)
                );
            } else {
                controller.renderError(404);
            }
            break;
        case ValidateRenderType.JSON:
            controller.renderJson(
                    Ret.fail("message", message)
                            .set("errorCode", errorCode)
                            .setIfNotNull("formName", formName)
            );
            break;
        case ValidateRenderType.REDIRECT:
            controller.redirect(redirectUrl);
            break;
        case ValidateRenderType.HTML:
            controller.render(htmlPath);
            break;
        case ValidateRenderType.TEXT:
            controller.renderText(message);
            break;
        default:
            throw new IllegalArgumentException("can not process render : " + renderType);
    }
}
 
Example 2
Source File: JbootShiroInvokeListener.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void doProcessUnauthenticated(Controller controller) {
    if (StrUtil.isBlank(config.getLoginUrl())) {
        controller.renderError(401);
        return;
    }
    controller.redirect(config.getLoginUrl());
}
 
Example 3
Source File: JbootShiroInvokeListener.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void doProcessuUnauthorization(Controller controller) {
    if (StrUtil.isBlank(config.getUnauthorizedUrl())) {
        controller.renderError(403);
        return;
    }
    controller.redirect(config.getUnauthorizedUrl());
}
 
Example 4
Source File: ProductValidate.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void intercept(Invocation inv) {

    Controller c = inv.getController();

    Long productId = inv.getController().getLong("id");
    Product product = productService.findById(productId);

    if (product == null || !product.isNormal()) {
        if (RequestUtil.isAjaxRequest(c.getRequest())) {
            c.renderJson(Ret.fail().set("code", "2").set("message", "商品不存在或已下架。"));
        } else {
            c.renderError(404);
        }
        return;
    }


    User user = UserInterceptor.getThreadLocalUser();
    if (user == null) {
        if (RequestUtil.isAjaxRequest(c.getRequest())) {
            c.renderJson(Ret.fail()
                    .set("code", 1)
                    .set("message", "用户未登录")
                    .set("gotoUrl", JFinal.me().getContextPath() + "/user/login?gotoUrl=" + product.getUrl()));
        } else {
            c.redirect("/user/login?gotoUrl=" + product.getUrl());
        }
        return;
    }

    c.setAttr(ATTR_PRODUCT,product);
    inv.invoke();
}